Qt 6.8 and ShowEvent being called twice
-
I was trying to set some stuff up that needed to be done once the display is actually open, so I initially had the code in
void Foo::showEvent(QShowEvent * event) { QDialog::showEvent(event); qDebug()<<"test"; QTimer::singleShot(0, this, &Foo::doStuff); }
doStuff throws up some more GUI items that take focus. Everything was working as expected with Qt6.5 and lower, and "test" is printed out once.
On the upgrade to Qt6.8, "test" is now printed out twice, and the dialog has focus rather than the child controls which I was trying to give focus too.
This is on Red Hat 8.
Is there a better way now to do stuff that will be executed after the dialog is officially shown? And is showEvent now going to be called multiple times, rather than once?
(Even if I remove everything, so it's just the dialog constructor and showEvent, the constructor is called once, whereas showEvent is called twice.)
-
Doing such stuff in showEvent() is not a good idea - it is e.g. also called when the window is minimized and restored. Why it happens in your case - I don't know. Maybe you can find out by looking at the backtrace during debugging. Maybe set a flag in doStuff to do it only once.