Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Moc not generating functions
Qt 6.12 LTS is out! See what's new in the release blog

Moc not generating functions

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 3 Posters 3.1k Views 2 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.
  • Christian EhrlicherC Christian Ehrlicher

    @Redman said in Moc not generating functions:

    SOURCES +=
    $$files("$$PWD/*.cpp",true) \

    Apart from the really strange way to add sources - this does not add configuration.cpp.

    As you can see in the linker error not the moc stuff is missing but the functions defined in configuration.cpp

    R Offline
    R Offline
    Redman
    wrote on last edited by
    #7

    @Christian-Ehrlicher
    Any tips on how to add sources without typing every file specifically. I assumed as long as the files showed up in the project tree building them is no problem. Which was true until now.

    Christian EhrlicherC 1 Reply Last reply
    0
    • R Redman

      @Christian-Ehrlicher
      Any tips on how to add sources without typing every file specifically. I assumed as long as the files showed up in the project tree building them is no problem. Which was true until now.

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #8

      @Redman Type all. But that's not the problem here.

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

      R 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @Redman Type all. But that's not the problem here.

        R Offline
        R Offline
        Redman
        wrote on last edited by
        #9

        @Christian-Ehrlicher So how can I tell moc to add the functions?

        Christian EhrlicherC 1 Reply Last reply
        0
        • R Redman

          @Christian-Ehrlicher So how can I tell moc to add the functions?

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #10

          @Redman said in Moc not generating functions:

          @Christian-Ehrlicher So how can I tell moc to add the functions?

          As I already said there is no problem with moc but you don't compile configuration.cpp anywhere.

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

          R 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @Redman said in Moc not generating functions:

            @Christian-Ehrlicher So how can I tell moc to add the functions?

            As I already said there is no problem with moc but you don't compile configuration.cpp anywhere.

            R Offline
            R Offline
            Redman
            wrote on last edited by
            #11

            @Christian-Ehrlicher
            The service.exe, which is configured in app.pro, is built correct. The exe can only be a result of a successful compilation. So I'd assume configuration.cpp is compiled

            Christian EhrlicherC 1 Reply Last reply
            0
            • R Redman

              @Christian-Ehrlicher
              The service.exe, which is configured in app.pro, is built correct. The exe can only be a result of a successful compilation. So I'd assume configuration.cpp is compiled

              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #12

              @Redman said in Moc not generating functions:

              So I'd assume configuration.cpp is compiled

              Don't assume, check.
              You did not show any pro file where you compile configuration.cpp so my answer still stands...

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

              R 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @Redman said in Moc not generating functions:

                So I'd assume configuration.cpp is compiled

                Don't assume, check.
                You did not show any pro file where you compile configuration.cpp so my answer still stands...

                R Offline
                R Offline
                Redman
                wrote on last edited by Redman
                #13

                @Christian-Ehrlicher
                758ed0ad-61b4-482a-a62c-d0270c00b542-image.png

                I think this should answer your question.

                To elaborate further:
                project.pro

                
                  SUBDIRS = \
                            client \
                            logger \
                            service
                			
                  # where to find the sub projects - give the folders
                  client.subdir = src/client
                  logger.subdir  = src/logger
                  service.subdir  = src/service
                

                service.pro

                TEMPLATE = subdirs
                
                SUBDIRS = \
                        app \
                        test \
                
                # where to find the sub projects - give the folders
                app.subdir = app
                test.subdir  = test
                
                test.depends = app
                

                So far all I had to do was include the sources and headers in the pro files and the projects simply compiled. Please enlighten me if I'm missing something crucial.

                update:
                After dumpbin.exe Configuration.obj /disasm

                ff927410-59f9-42c8-ac13-8b3dd1da0302-image.png

                Even though we see the function is present in the obj file I still get following error

                error: LNK2019: unresolved external symbol ""public: __cdecl Configuration::Configuration(class QObject *)" (??0Configuration@@QEAA@PEAVQObject@@@Z)" in function ""private: static void __cdecl TestConfig::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@TestConfig@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z)".

                What makes me wonder is the second part of the error message. But I guess thats just how Qt invokes all function calls for classes that inherit from QObject.

                Christian EhrlicherC 1 Reply Last reply
                0
                • R Redman

                  @Christian-Ehrlicher
                  758ed0ad-61b4-482a-a62c-d0270c00b542-image.png

                  I think this should answer your question.

                  To elaborate further:
                  project.pro

                  
                    SUBDIRS = \
                              client \
                              logger \
                              service
                  			
                    # where to find the sub projects - give the folders
                    client.subdir = src/client
                    logger.subdir  = src/logger
                    service.subdir  = src/service
                  

                  service.pro

                  TEMPLATE = subdirs
                  
                  SUBDIRS = \
                          app \
                          test \
                  
                  # where to find the sub projects - give the folders
                  app.subdir = app
                  test.subdir  = test
                  
                  test.depends = app
                  

                  So far all I had to do was include the sources and headers in the pro files and the projects simply compiled. Please enlighten me if I'm missing something crucial.

                  update:
                  After dumpbin.exe Configuration.obj /disasm

                  ff927410-59f9-42c8-ac13-8b3dd1da0302-image.png

                  Even though we see the function is present in the obj file I still get following error

                  error: LNK2019: unresolved external symbol ""public: __cdecl Configuration::Configuration(class QObject *)" (??0Configuration@@QEAA@PEAVQObject@@@Z)" in function ""private: static void __cdecl TestConfig::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@TestConfig@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z)".

                  What makes me wonder is the second part of the error message. But I guess thats just how Qt invokes all function calls for classes that inherit from QObject.

                  Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #14

                  Provide a minimal, compilable example. Don't use global globs to add files so we can see where exactly configuration.cpp is compiled into since you still (after 5 posts from me) failed to do so.

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

                  R 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    Provide a minimal, compilable example. Don't use global globs to add files so we can see where exactly configuration.cpp is compiled into since you still (after 5 posts from me) failed to do so.

                    R Offline
                    R Offline
                    Redman
                    wrote on last edited by Redman
                    #15

                    @Christian-Ehrlicher Here you go
                    https://file.io/dO55Ata0j6rm
                    https://easyupload.io/bwbtos

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • R Redman

                      @Christian-Ehrlicher Here you go
                      https://file.io/dO55Ata0j6rm
                      https://easyupload.io/bwbtos

                      Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #16

                      As I said - there is no library where you link your configuration.cpp - you only compile it directly to your app.
                      So either also directly link it to your testcase or create a library and link the library to your app and your test.

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

                      1 Reply Last reply
                      3
                      • R Redman

                        @Christian-Ehrlicher
                        #ifndef CONFIGURATION_H is present. I missed it while copying.

                        My project structure:
                        457dd8ba-0012-4297-8a30-71d318db39b5-image.png

                        test.pro

                        QT += testlib
                        QT -= gui
                        
                        TARGET = TestService
                        
                        CONFIG += qt console warn_on depend_includepath testcase
                        CONFIG -= app_bundle
                        CONFIG -= debug_and_release
                        
                        TEMPLATE = app
                        
                        SOURCES += \
                            $$files("$$PWD/src/*.cpp", true)
                        
                        S Offline
                        S Offline
                        SimonSchroeder
                        wrote on last edited by
                        #17

                        @Redman said in Moc not generating functions:

                        SOURCES +=
                        $$files("$$PWD/src/*.cpp", true)

                        If you insist on using this any further, you need to adjust your paths. To add configuration.cpp to your test.pro the path needs to be $$PWD/../app/src/*.cpp because $$PWD is service/test, but your sources are locate in service/app/src. $$PWD stands for "print working directory" and thus your working directory for app.pro and test.pro is different.

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          Redman
                          wrote on last edited by
                          #18

                          Solution was to create SUBDIR .pro with lib and test subdirs. In lib I build a .dll from app and include the dll in test
                          1c411b43-060b-429b-9589-0f8263271149-image.png

                          1 Reply Last reply
                          0
                          • R Redman has marked this topic as solved on

                          • Login

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