Show QDialog before MainWindow



  • Hello,
    I try to show a login panel (QDialog) before my MainWindow is shown to the user.
    At least on a Mac I see following inconsistent behavior:
    The login panel always shows up before the MainWindow which is the correct behavior.
    But then in about 50% of the cases this login panel freezes and the mac beach ball rolls for maybe 5 seconds before it unfreezes by itself again. After that everything is normal.
    In the other 50% of the cases, everything works perfectly as expected.
    Here is the relevant code:

    @
    #include "mainwindow.h"
    #include <QApplication>
    #include <QDialog>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    MainWindow w;

    QDialog loginDialog(NULL);
    loginDialog.exec();

    w.show();

    return a.exec();
    }
    @

    I don't see this problem, if I move the w.show() line in front of the QDialog instantiation.
    But then obviously my MainWindow already shows behind the login dialog, which I would like to avoid.

    Is this a bug in QT?

    Thanks
    Stefan

    [edit: added missing coding tags @ SGaist]



  • I have done this within the MainWindow constructor, before @ui.setupUi(this)@

    loads the main window.

    Your code should really be formatted using the coding tag to make it more readable.

    Here is an example of the code that works for me on Linux and Windows.

    As I say this happens within the constructor of MainWindow and before I do this I read my configuration and use that configuration to connect to my database, which holds the login information and the database connection is passed to the login dialogue.

    I am typing this in rather than cutting and pasting so I have left out the Signal/Slot code.

    @
    Login_Dialog* loginDialog = new Login_Dialog(m_db, this);
    // I then set up the signals and slots to interact with the Login Dialog

    loginDialog->exec();

    ui->setupUi(this);
    @

    I then have some code that closes the main window if the login either cancels or fails to log in.


  • Lifetime Qt Champion

    Hi,

    Your code looks fine so far, what happens if you do something like that:

    @
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    QDialog loginDialog(NULL);
    loginDialog.exec();

    MainWindow w;
    w.show();

    return a.exec();
    }
    @

    By the way, which version of Qt and OS X are you using ?



  • Hi SGaist,

    moving the MainWindow instantiation down leads to the same inconsistent behavior.

    Qt 5.3.2
    Mac OS 10.10.0


  • Lifetime Qt Champion

    Can you try with the 5.4 beta ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.