[SOLVED] QtSingleApplication crashes on Windows (Qt 5.4)



  • The latest (updated about a year ago) QtSingleApplication from Qt Extras repository crashes on Windows on program startup. The crash occurs pretty often - like every 5th startup. Has anyone encountered this problem, is there a solution?
    I couldn't really debug it because it only crashes in release build. I see where it crashes, but don't understand why. It's a memory management issue (invalid pointers).


  • Lifetime Qt Champion

    Hi,

    Does the break happen in your code or in Qt's ?



  • Hi,

    It happens in qtsingleapplication.cpp


  • Lifetime Qt Champion

    Can you give more details ?



  • Not much more, I'm afraid. There is a method QtSingleApplication::activateWindow(). It's a slot, and it's sometimes called on invalid pointer, i. e. QtSingleApplication's this is garbage when activateWindow is called. I've tried replacing regular good old connect calls with the new compile-time ones (that take a method pointer instead of a method name), then it started crashing when calling other slots (that I didn't yet touch).
    This is all during normal startup - in absence of another instance of the application.


  • Lifetime Qt Champion

    Not even a stack trace ?



  • Sure, I'll post a trace (for whatever it's worth in release build) tomorrow.



  • I've found the problem! It was a user error, not a QtSingleApplication bug.
    My application is doing some deinitialization work after the main window is closed and app.exec() returns. If another instance attempts to start while this work is being done, it will attempt to activate the first instance's window that's no longer being processed in the event loop. I'm not sure exactly why or how, but it causes crash. Solution: call app.setActivationWindow(nullptr); right after app.exec(). Or better yet, call it in the QMainWindow::closeEvent.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.