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. Why does trying to create multiple windows when an application starts only create one?
Forum Updated to NodeBB v4.3 + New Features

Why does trying to create multiple windows when an application starts only create one?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 419 Views 4 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.
  • Guy GizmoG Offline
    Guy GizmoG Offline
    Guy Gizmo
    wrote on last edited by
    #1

    If I execute the following code, only one window will open:

    int main(int argc, char *argv[])
    {    
        QApplication a(argc, argv);
        QWidget *w1 = new QWidget;
        w1->show();
        QWidget *w2 = new QWidget;
        w2->show();
        return a.exec();
    }
    

    However, this in this case both windows open:

    int main(int argc, char *argv[])
    {    
        QApplication a(argc, argv);
        QTimer::singleShot(200, [] () {
            QWidget *w1 = new QWidget;
            w1->show();
            QWidget *w2 = new QWidget;
            w2->show();
        });
        return a.exec();
    }
    

    If I set the timer's timeout to 0 or generally any value less than 100, then it doesn't work then either.

    Can anyone tell me what's going on? Why does it only work when I use a timer with a sufficiently long timeout?

    I'm building this on macOS with Qt 6.2.4.

    M 1 Reply Last reply
    0
    • Guy GizmoG Guy Gizmo

      If I execute the following code, only one window will open:

      int main(int argc, char *argv[])
      {    
          QApplication a(argc, argv);
          QWidget *w1 = new QWidget;
          w1->show();
          QWidget *w2 = new QWidget;
          w2->show();
          return a.exec();
      }
      

      However, this in this case both windows open:

      int main(int argc, char *argv[])
      {    
          QApplication a(argc, argv);
          QTimer::singleShot(200, [] () {
              QWidget *w1 = new QWidget;
              w1->show();
              QWidget *w2 = new QWidget;
              w2->show();
          });
          return a.exec();
      }
      

      If I set the timer's timeout to 0 or generally any value less than 100, then it doesn't work then either.

      Can anyone tell me what's going on? Why does it only work when I use a timer with a sufficiently long timeout?

      I'm building this on macOS with Qt 6.2.4.

      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #3

      @Guy-Gizmo
      Hi,
      The two windows are showed, but
      they have the same size, so one may obscure the other,
      and often the second one is behind QCreator IDE, clicking on the app in the dock brings all the two windows in front.

      Guy GizmoG 1 Reply Last reply
      1
      • C Offline
        C Offline
        CPPUIX
        wrote on last edited by
        #2

        Hi,

        I cannot reproduce this on KDE Neon with Qt 6.5.0.

        Can you run through it with a debugger, and see what happens exactly?

        Guy GizmoG 1 Reply Last reply
        0
        • Guy GizmoG Guy Gizmo

          If I execute the following code, only one window will open:

          int main(int argc, char *argv[])
          {    
              QApplication a(argc, argv);
              QWidget *w1 = new QWidget;
              w1->show();
              QWidget *w2 = new QWidget;
              w2->show();
              return a.exec();
          }
          

          However, this in this case both windows open:

          int main(int argc, char *argv[])
          {    
              QApplication a(argc, argv);
              QTimer::singleShot(200, [] () {
                  QWidget *w1 = new QWidget;
                  w1->show();
                  QWidget *w2 = new QWidget;
                  w2->show();
              });
              return a.exec();
          }
          

          If I set the timer's timeout to 0 or generally any value less than 100, then it doesn't work then either.

          Can anyone tell me what's going on? Why does it only work when I use a timer with a sufficiently long timeout?

          I'm building this on macOS with Qt 6.2.4.

          M Offline
          M Offline
          mpergand
          wrote on last edited by mpergand
          #3

          @Guy-Gizmo
          Hi,
          The two windows are showed, but
          they have the same size, so one may obscure the other,
          and often the second one is behind QCreator IDE, clicking on the app in the dock brings all the two windows in front.

          Guy GizmoG 1 Reply Last reply
          1
          • C CPPUIX

            Hi,

            I cannot reproduce this on KDE Neon with Qt 6.5.0.

            Can you run through it with a debugger, and see what happens exactly?

            Guy GizmoG Offline
            Guy GizmoG Offline
            Guy Gizmo
            wrote on last edited by
            #4

            @Abderrahmene_Rayene said in Why does trying to create multiple windows when an application starts only create one?:

            Hi,

            I cannot reproduce this on KDE Neon with Qt 6.5.0.

            Can you run through it with a debugger, and see what happens exactly?

            The code executes normally. There are no errors or crashes. But the second window never opens. Does that answer your question?

            1 Reply Last reply
            0
            • M mpergand

              @Guy-Gizmo
              Hi,
              The two windows are showed, but
              they have the same size, so one may obscure the other,
              and often the second one is behind QCreator IDE, clicking on the app in the dock brings all the two windows in front.

              Guy GizmoG Offline
              Guy GizmoG Offline
              Guy Gizmo
              wrote on last edited by
              #5

              @mpergand said in Why does trying to create multiple windows when an application starts only create one?:

              @Guy-Gizmo
              Hi,
              The two windows are showed, but
              they have the same size, so one may obscure the other,
              and often the second one is behind QCreator IDE, clicking on the app in the dock brings all the two windows in front.

              I can confirm the issue is not that one window is obscured by the other, or appearing behind other windows. There's only one window that opens.

              I've reproduced the issue in both Qt 6.2.4 and Qt 5.15.2, both on macOS. I wonder if this is a macOS specific issue?

              Guy GizmoG M 2 Replies Last reply
              0
              • Guy GizmoG Guy Gizmo

                @mpergand said in Why does trying to create multiple windows when an application starts only create one?:

                @Guy-Gizmo
                Hi,
                The two windows are showed, but
                they have the same size, so one may obscure the other,
                and often the second one is behind QCreator IDE, clicking on the app in the dock brings all the two windows in front.

                I can confirm the issue is not that one window is obscured by the other, or appearing behind other windows. There's only one window that opens.

                I've reproduced the issue in both Qt 6.2.4 and Qt 5.15.2, both on macOS. I wonder if this is a macOS specific issue?

                Guy GizmoG Offline
                Guy GizmoG Offline
                Guy Gizmo
                wrote on last edited by
                #6

                @Guy-Gizmo said in Why does trying to create multiple windows when an application starts only create one?:

                @mpergand said in Why does trying to create multiple windows when an application starts only create one?:

                @Guy-Gizmo
                Hi,
                The two windows are showed, but
                they have the same size, so one may obscure the other,
                and often the second one is behind QCreator IDE, clicking on the app in the dock brings all the two windows in front.

                I can confirm the issue is not that one window is obscured by the other, or appearing behind other windows. There's only one window that opens.

                I've reproduced the issue in both Qt 6.2.4 and Qt 5.15.2, both on macOS. I wonder if this is a macOS specific issue?

                Wait, no, false alarm! I'm dumb. The windows are appearing behind Qt Creator. I don't know how I missed that.

                Please disregard!

                1 Reply Last reply
                0
                • Guy GizmoG Guy Gizmo has marked this topic as solved on
                • Guy GizmoG Guy Gizmo

                  @mpergand said in Why does trying to create multiple windows when an application starts only create one?:

                  @Guy-Gizmo
                  Hi,
                  The two windows are showed, but
                  they have the same size, so one may obscure the other,
                  and often the second one is behind QCreator IDE, clicking on the app in the dock brings all the two windows in front.

                  I can confirm the issue is not that one window is obscured by the other, or appearing behind other windows. There's only one window that opens.

                  I've reproduced the issue in both Qt 6.2.4 and Qt 5.15.2, both on macOS. I wonder if this is a macOS specific issue?

                  M Offline
                  M Offline
                  mpergand
                  wrote on last edited by
                  #7

                  @Guy-Gizmo said in Why does trying to create multiple windows when an application starts only create one?:

                  I've reproduced the issue in both Qt 6.2.4 and Qt 5.15.2, both on macOS

                  I'm in Qt 5.15.2 macOs 10.15 and that's not the case for me.

                  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