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. MessageBox with MinWG
Forum Updated to NodeBB v4.3 + New Features

MessageBox with MinWG

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 1.9k 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by
    #1

    I created a subclass MessageBox of QMessageBox that has some static functions, including one named error. Using these functions elsewhere gives a compilation error with MinWG but not with gcc. The error looks a bit odd:

    error: undefined reference to `MessageBoxW::error(QString const&, QString const&, QFlags<QMessageBox::StandardButton>, QWidget*)'
    

    The oddity for me is in the letter W after MessageBox in the reference. When diving into this, I found that there is a global #define in winuser.h as follows:

    #define MessageBox __MINGW_NAME_AW(MessageBox)
    

    which already claims the MessageBox symbol. Replacing the above code in winuser.h into for example

    #define MINWGMessageBox __MINGW_NAME_AW(MessageBox)
    

    solves my compilation problem and the application runs correctly.

    Has anyone encountered this problem before? Is it save to fix the problem in winuser.h or should I better rename my class (not really my preference)?

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

      Hi and welcome to devnet,

      No it's not safe to fiddle with winuser.h. See here for more information about the MessageBox macro.

      Short version: MessageBox is a Windows API wrapped in a macro by MinGW to get the correct function.

      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
      • ModelTechM Offline
        ModelTechM Offline
        ModelTech
        wrote on last edited by
        #3

        That's what I guessed as well...

        Now, I got the opportunity to use the msvc2012 compiler for the same code which also gives a compiler error, with a similar oddity

        mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: static int __cdecl MessageBoxW::error(class QString const &,class QString const &,class QFlags<enum QMessageBox::StandardButton>,class QWidget *)" (?error@MessageBoxW@@SAHABVQString@@0V?$QFlags@W4StandardButton@QMessageBox@@@@PAVQWidget@@@Z) referenced in function "private: void __thiscall MainWindow::openFile(void)" (?openFile@MainWindow@@AAEXXZ)
        

        Is renaming my MessageBox class the only way out here?

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Is renaming my MessageBox class the only way out here?

          no, this is exactly the reason namespaces were invented

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          3
          • ModelTechM Offline
            ModelTechM Offline
            ModelTech
            wrote on last edited by ModelTech
            #5

            Yes, of course! Didn't think about that. I am still too much of a C++ novice...

            Solved :)

            1 Reply Last reply
            0

            • Login

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