Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Show QDialog before MainWindow
Forum Updated to NodeBB v4.3 + New Features

Show QDialog before MainWindow

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nohoo77
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mikeosoft
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nohoo77
          wrote on last edited by
          #4

          Hi SGaist,

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

          Qt 5.3.2
          Mac OS 10.10.0

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Can you try with the 5.4 beta ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved