Why does trying to create multiple windows when an application starts only create one?
-
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.
-
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.
@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. -
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.
@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. -
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?
@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?
-
@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.@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?
-
@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-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!
-
G Guy Gizmo has marked this topic as solved on
-
@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-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.