Debugger doesn't stop after closing app
-
Hi,
I've got a new computer with Linux Mint 22 instead of 20 and went from Qt 6.3 to 6.8.1, and now the debugger doesn't stop anymore most of the time and I have no idea why.
Basically, the apps seem to close fine (I see no windows, the app doesn't show up as a process and I can even start a new debugging session in Qt Creator), but I have to manually click on the "Stop running program." button under "Application output. When I try to close the application output window (or Qt Creator) I get this error message:
Admittedly, I'm a bad programmer and don't know what I'm doing half of the time, but I experimented a little with deleting widgets via delete and it didn't change anything and I have no idea how to find the culprit (they are pretty big projects).
A completely new project works fine. If I close the window immediately after showing it I have the same problem:
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); w.close();//with this debugger doesn't stop return a.exec(); }
Any ideas what the problem might be? Thanks.
Best wishes,
Angela -
-
Hi, I've reproduced the mini-demo you said, I think the key point is that it doesn't go through the exec function.even if it's a little bit of change
MainWindow w; w.show(); // w.close(); QTimer::singleShot(0, &w, &MainWindow::close); return a.exec();
About the program's occasional failure to exit normally,I was guessing if it might need to be set QGuiApplication::setQuitOnLastWindowClosed, or QWidget::setAttribute(Qt::WA_QuitOnClose), But in this case it should be a sure phenomenon.
I suggest you try to focus on the events of the root widget, if it prints
QEvent::Destroy
, Qt's event loop already tells it that can leave work, the next focus are the release of each object...It may be that some thread is not exiting, or is waiting for him to exit.Finally, I attach how I listened to my events
void* WatchedObj = nullptr; class Snow : public QObject { using super = QObject; using super::super; public: ~Snow() { qDebug() << "destroy"; } public: bool eventFilter(QObject *watched, QEvent *event) override { if(WatchedObj == watched) { qDebug() << event->type(); } return super::eventFilter(watched, event); } }; int main(int argc, char *argv[]) { QApplication a(argc, argv); Snow s; MainWindow w; WatchedObj = &w; w.installEventFilter(&s); w.show(); QTimer::singleShot(2000, qApp, &QCoreApplication::quit); return a.exec(); }
-
Thanks for the reply.
Unfortunately, neither QGuiApplication::setQuitOnLastWindowClosed, nor QWidget::setAttribute(Qt::WA_QuitOnClose) made a difference.
Destroy is called. Here are all events at closing
QEvent::Close
QEvent::Hide
QEvent::HideToParent
QEvent::PlatformSurface
QEvent::WinIdChange
QEvent::UpdateRequest
QEvent::ChildRemoved
QEvent::Destroy
destroyI've commented out everything that creates anything, so that I've got your example with MainWindow just returning before doing anything, but the problem persists.
-
There's a number of messages/warnings on application start that I haven't looked into yet. Could that have anything to do with it? I get the same warnings with the fresh application, though.
OK, apparently I can't post the warnings saying it's spam. They all start with "could not find '.gnu_debugaltlink' file for " and than some library.
-
Update: after a lot of trial and error I got 2 of my 3 apps to quit correctly by disabling QML debugging. But somehow I've made the 3rd app worse. Here's the events at close now:
QEvent::Close
QEvent::InputMethodQuery
QEvent::WindowDeactivate
QEvent::ActivationChange
QEvent::Hide
QEvent::HideToParent
QEvent::PlatformSurface
QEvent::WinIdChange
QEvent::LayoutRequest
QEvent::UpdateRequestNo Destroy is called and the debugger really doesn't stop.
-
OK, so apparently I have to manually remove a dock widget when closing the app. God knows why, but everything seems to work now. Fingers crossed.
-
-
@angela2016
I come a little late to the party, since you have now marked the topic as solved. So I don't know if you are still interested.Your original code read:
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); w.close();//with this debugger doesn't stop return a.exec(); }
Here you have no visible window, since you close the the only window before you call
a.exec()
. This will result in a Qt program which continues to run the event loop but since it has no visible window you won't "see" anything. That does not mean it is not still running. If you useps
you can see the process is still in existence. Hence the debugger won't exit and will ask you if you want to terminate the subprocess. If you run it outside of debugger you will leave a process running forever but invisible.Note that this will not be affected by Qt's default
quitOnLastWindowClosed
being true, since you do not close any/the last window while the event loop is running (you closed it beforehand). That is why delaying it with aQTimer::singleShot()
will make it quit.At the end you say the problem is solved by "manually remove a dock widget when closing the app". But your code has no dock widget so I have no idea how that is relevant.
-
The code above was just my attempt to create a minimal reproducible example because I had this problem with all of my 3 programs which are all pretty large and I couldn't come up with a small program that had the same issue other than this silly example.
The dock widget, however, refers to one of my actual programs. That is, the problem with all 3 was the QML debugger being enabled and on top of that one of the programs needed the dock widget closed. I just thought I'd write it down in case someone has a similar problem and finds this post.