Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Qt 6 undefined reference to `qMain(int, char**)'
Forum Updated to NodeBB v4.3 + New Features

Qt 6 undefined reference to `qMain(int, char**)'

Scheduled Pinned Locked Moved Unsolved Qt 6
15 Posts 7 Posters 3.6k 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.
  • C Christian Ehrlicher
    30 Jan 2024, 07:07

    Then simplify your code to a minimal example with a proper pro file.

    H Offline
    H Offline
    HeJianglong
    wrote on 30 Jan 2024, 07:52 last edited by
    #6

    @Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)':

    Then simplify your code to a minimal example with a proper pro file.

    I can compile correctly in qt6.6.0.

    C 1 Reply Last reply 30 Jan 2024, 17:22
    0
    • H HeJianglong
      30 Jan 2024, 07:52

      @Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)':

      Then simplify your code to a minimal example with a proper pro file.

      I can compile correctly in qt6.6.0.

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 30 Jan 2024, 17:22 last edited by Christian Ehrlicher
      #7

      Sometimes I wonder if people don't know what minimal means...

      This works fine for me with Qt6.6.1/MinGW

      #include <QApplication>
      
      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);    
          return app.exec();
      }
      
      TEMPLATE = app
      TARGET = tmp
      INCLUDEPATH += .
      QT += widgets
      SOURCES += main.cpp
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      H 1 Reply Last reply 31 Jan 2024, 01:27
      2
      • C Christian Ehrlicher
        30 Jan 2024, 17:22

        Sometimes I wonder if people don't know what minimal means...

        This works fine for me with Qt6.6.1/MinGW

        #include <QApplication>
        
        int main(int argc, char **argv)
        {
            QApplication app(argc, argv);    
            return app.exec();
        }
        
        TEMPLATE = app
        TARGET = tmp
        INCLUDEPATH += .
        QT += widgets
        SOURCES += main.cpp
        
        H Offline
        H Offline
        HeJianglong
        wrote on 31 Jan 2024, 01:27 last edited by
        #8

        @Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)':

        Sometimes I wonder if people don't know what minimal means...

        This works fine for me with Qt6.6.1/MinGW

        #include <QApplication>
        
        int main(int argc, char **argv)
        {
            QApplication app(argc, argv);    
            return app.exec();
        }
        
        TEMPLATE = app
        TARGET = tmp
        INCLUDEPATH += .
        QT += widgets
        SOURCES += main.cpp
        

        When I use the example you provided is normal.

        I don't know how to troubleshoot this problem now, because some of my projects can be compiled, and some have this problem.

        C 1 Reply Last reply 31 Jan 2024, 05:17
        0
        • H HeJianglong
          31 Jan 2024, 01:27

          @Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)':

          Sometimes I wonder if people don't know what minimal means...

          This works fine for me with Qt6.6.1/MinGW

          #include <QApplication>
          
          int main(int argc, char **argv)
          {
              QApplication app(argc, argv);    
              return app.exec();
          }
          
          TEMPLATE = app
          TARGET = tmp
          INCLUDEPATH += .
          QT += widgets
          SOURCES += main.cpp
          

          When I use the example you provided is normal.

          I don't know how to troubleshoot this problem now, because some of my projects can be compiled, and some have this problem.

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 31 Jan 2024, 05:17 last edited by
          #9

          Then simplify your projects until it works - a normal devleoper task.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          H 1 Reply Last reply 1 Feb 2024, 01:22
          1
          • C Christian Ehrlicher
            31 Jan 2024, 05:17

            Then simplify your projects until it works - a normal devleoper task.

            H Offline
            H Offline
            HeJianglong
            wrote on 1 Feb 2024, 01:22 last edited by
            #10

            @Christian-Ehrlicher said in Qt 6 undefined reference to `qMain(int, char**)':

            Then simplify your projects until it works - a normal devleoper task.

            Thanks, I think I can get rid of the libraries I'm using and try again

            1 Reply Last reply
            0
            • Y Offline
              Y Offline
              yeontak
              wrote on 14 Feb 2024, 07:24 last edited by
              #11

              Did you solve it?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                changshou
                wrote on 7 Mar 2024, 01:40 last edited by
                #12

                The same problem as you. Have you solved it? Please help me

                1 Reply Last reply
                1
                • Q Offline
                  Q Offline
                  qt_john_doe
                  wrote on 4 Apr 2024, 11:48 last edited by
                  #13

                  There's a conflict between your code and a macro #define main qMain defined in include/QtGui/qwindowdefs.h
                  which is used to avoid a console window in a Qt project (as per https://stackoverflow.com/a/18553402). You can rename any variables in your code named main or reduce/rearrange includes as others have proposed.

                  1 Reply Last reply
                  1
                  • Q Offline
                    Q Offline
                    Q74r3wq-
                    wrote on 26 Oct 2024, 18:57 last edited by
                    #14

                    I have encountered the same error with a library I'm using (SDL2). I don't know whether it is the same library that is causing the issue, but for SDL2 I need to put up a macro to tell it that main() is being handled elsewhere (by QT):

                    #include <QApplication>
                    #define SDL_MAIN_HANDLED
                    #include <SDL2/SDL.h>
                    

                    Hope it helps!

                    1 Reply Last reply
                    1
                    • QtFriend2024Q Offline
                      QtFriend2024Q Offline
                      QtFriend2024
                      wrote 24 days ago last edited by QtFriend2024
                      #15

                      ** MY SOLUTION **

                      I had this same issue with my QT Widgets project using Windows 11 host machine. I had upgraded my QT to 6.8.3 and this Error: undefined reference to `qMain(int, char)'** even though this wasn't the actual issue . Following my steps below, Qt Creator was able to highlight the actual issues for me to resolve and successfully build my project.

                      Steps to Resolve the Issue:

                      1. Create a new, most simple Qt Widgets project. Use the default mainwindow.h, mainwindow.cpp and mainwindow.ui
                        with the project kit that you want to use
                      2. Run CMake
                      3. Build the project. It should build successfully
                      4. Open the CMakeLists.txt file
                      5. Utilize this new, simple CMakeLists.txt file as a template for your ORIGINAL project.
                      6. Modify the "template" CMakeLists.txt file to include your original project's resource file names where you see main.cpp, mainwindow.h, mainwindow.cpp, etc.
                      7. Modify the "template" CMakeLists.txt file to include the QT packages you are using (Core, Gui, or etc.)
                      8. Modify the "template" CMakeLists.txt file to include the target link libraries (refer to packages in previous step)
                      9. Build your original project
                      10. It should give you more specific, helpful errors to resolve (if there are any). For me, one of my *.cpp files #include Qt Serial Bus but I forgot to add it to CMakeLists.txt
                      11. Resolve errors
                      12. Rebuild. It built successfully for me.
                      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