Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMessageBox works in Linux but not Windows
Forum Updated to NodeBB v4.3 + New Features

QMessageBox works in Linux but not Windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 528 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ellend
    wrote on last edited by ellend
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Where are retryCallback and successCallback called from ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ellend
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Is that object connect through signals and slots ?

          Those are two different OS with different execution models.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • E Offline
            E Offline
            ellend
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved