Project

General

Profile

Rookie question on WDialog::hide()

Added by Mike Strom over 11 years ago

Hi,

in the code below, i try to hide the login window (mDialog) during the lengthy login process. As it is now, the user can press OK button and trigger parallel login calls. I need to disable the mDialog or the button (which also failed).

LoginWidget::LoginWidget(App *app)
:   mApp(app)
{
    mDialog = new WDialog("Login", app->root());

    WLabel *label = new WLabel("Username", mDialog->contents());
    mUsername = new WLineEdit(mDialog->contents());
    label->setBuddy(mUsername);

    new WBreak(mDialog->contents());

    label = new WLabel("Password", mDialog->contents());
    mPassword = new WLineEdit(mDialog->contents());
    mPassword->setEchoMode(WLineEdit::Password);
    label->setBuddy(mPassword);

    new WBreak(mDialog->contents());

    mButtonOk = new WPushButton("OK", mDialog->footer());

    mButtonOk->clicked().connect(this, &LoginWidget::btnLoginPressed);
    mPassword->enterPressed().connect(this, &LoginWidget::btnLoginPressed);

    mDialog->show();
}

//------------------------------------------------------------------------------

void LoginWidget::btnLoginPressed()
{
    mDialog->hide();  //--- hide() fails here

    mApp->GetClient().Login();  // This a locks the main thread for a few seconds

    mDialog->show();

    // ...
}

This does not work, the mDialog is never hidden. What am i doing wrong?

I have also tried mDialog~~disable() / mDialog~~>enable(), but it does not work either. In Qt, i would do a manual MessagePump() call to get it to work, but i can't find anything like that in Wt

Thanks in advance!


Replies (2)

RE: Rookie question on WDialog::hide() - Added by Wim Dumon over 11 years ago

WApplication::processEvents() is what you're looking for:

  wApp->processEvents();

Alterntively, start the login in a separate thread and use WApplication::deferRendering() and WApplication::resumeRendering().

Wim.

RE: Rookie question on WDialog::hide() - Added by Mike Strom over 11 years ago

Thanks Wim,

processEvents() worked like charm! How could i miss that?

/Mike

    (1-2/2)