Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QMessageBox works in Linux but not Windows



  • I have a program that I have compiled for both linux and windows. In linux everything runs smoothly, however in windows I get an error when I try to use a QMessageBox to pop up either a success or failure notice. The error says that all QWidgets must be in the main gui thread. The widgets are created and owned by the MainWindow which is entirely in the main thread (instantiated and used only in main). With identical code the executable runs smoothly in linux. Why is there a difference and what can I do to fix this on the windows side? I'm not even sure how to move the message boxes to the main thread (as indicated by the windows error) given that they are created and used by the mainwindow class which is already in the main thread.

    for example, I've added the code below showing the how the two QMessageBoxes are created by the MainWindow.

    void MainWindow::retryCallback()
    {
        QMessageBox popup(this);
        popup.critical(this, "Failed", "There was an error loading. Please try again.");
    }
    
    void MainWindow::successCallback()
    {
        QMessageBox popup(this);
        popup.information(this, "Complete", "The operation was successful");
    }
    

    Again, this code works totally fine in my linux application. In addition - I am able to use a QProgressDialog to pop up a progress bar in the same method. It is created and owned by the MainWindow and that doesn't cause any problems in either windows or linux.


  • Lifetime Qt Champion

    Hi,

    Where are retryCallback and successCallback called from ?



  • They are called from by a different object called ConnectionManager, which I believed was on the same thread but I can double check that. If it is on a different thread, could that be the problem? Do you know why this wouldn't be a problem in linux?


  • Lifetime Qt Champion

    Is that object connect through signals and slots ?

    Those are two different OS with different execution models.



  • No, it is not connected through singals and slots. Is that required for windows? I though that using QObjects would allow for cross-compiling. Is the implementation of those object different as well?


  • Lifetime Qt Champion

    Then that means that you are manipulating GUI objects from outside of the GUI thread which is something you should not do. It's just lucky that it is working on Linux.

    Cross-compilation has nothing to do with QObject. QObject is implemented the same on all platforms.

    The backend code might differ from one platform to the other because said platforms are different.


Log in to reply