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. qt - undefined reference to `vtable for myObj' in qt console application - signals and slots
Forum Updated to NodeBB v4.3 + New Features

qt - undefined reference to `vtable for myObj' in qt console application - signals and slots

Scheduled Pinned Locked Moved Unsolved General and Desktop
qobjectmacroclassvtableqt 5.7
11 Posts 7 Posters 8.3k Views 3 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.
  • hskoglundH Offline
    hskoglundH Offline
    hskoglund
    wrote on last edited by hskoglund
    #2

    Hi, the Q_OBJECT macro in your class declaration needs to be processed by the moc compiler. Easiest is to move your class declaration into your main.h.
    EDIT: forgot probably you don't have a main.h yet, if so, just create it and put the class declaration inside it. And don't forget to #include main.h in your main.cpp :-)

    1 Reply Last reply
    1
    • yuvaramY Offline
      yuvaramY Offline
      yuvaram
      wrote on last edited by yuvaram
      #3

      Hi CybeX,
      I have experimented your program. All the syntax are perfect, there is a issue with CLASS name (myObj).
      with class name myObj i m getting linker error.
      But by changing the class name and building there is no error. So may be there is some dependency issue with class name myObj.
      change it to myObj1 and try.

      Yuvaram Aligeti
      Embedded Qt Developer
      : )

      D 1 Reply Last reply
      0
      • yuvaramY yuvaram

        Hi CybeX,
        I have experimented your program. All the syntax are perfect, there is a issue with CLASS name (myObj).
        with class name myObj i m getting linker error.
        But by changing the class name and building there is no error. So may be there is some dependency issue with class name myObj.
        change it to myObj1 and try.

        D Offline
        D Offline
        Devopia53
        wrote on last edited by Devopia53
        #4

        @yuvaram

        Hi.

        You can just add the following line in main.cpp:

        [...]
        #include "main.moc"
        
        int main(int argc, char *argv[])
        {
        [...]
        
        

        and then run qmake.

        1 Reply Last reply
        1
        • yuvaramY Offline
          yuvaramY Offline
          yuvaram
          wrote on last edited by
          #5

          @Devopia53
          Thank for correcting.

          But after adding #include "main.moc", (run qmake is also done) following error while building.

          Error: dependent 'debug\main.moc' does not exist.

          Yuvaram Aligeti
          Embedded Qt Developer
          : )

          D 1 Reply Last reply
          0
          • yuvaramY yuvaram

            @Devopia53
            Thank for correcting.

            But after adding #include "main.moc", (run qmake is also done) following error while building.

            Error: dependent 'debug\main.moc' does not exist.

            D Offline
            D Offline
            Devopia53
            wrote on last edited by
            #6

            @yuvaram

            Really? :(

            I'm works fine.
            If so, you can delete all of the previously built directories and then save main.cpp and rebuild all. Also, check where the main.moc file is generated.

            Good luck!.

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

              Hi,

              If you really want to use that technique, the moc include should be the last line of main.cpp file

              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
              • yuvaramY Offline
                yuvaramY Offline
                yuvaram
                wrote on last edited by
                #8

                Hi ,
                main.moc file is not generating.

                Yuvaram Aligeti
                Embedded Qt Developer
                : )

                mrjjM D 2 Replies Last reply
                1
                • yuvaramY yuvaram

                  Hi ,
                  main.moc file is not generating.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #9

                  @yuvaram
                  Hi
                  For less pain. just use a .h file. :)

                  Delete the build folder and rebuild all.

                  1 Reply Last reply
                  1
                  • yuvaramY yuvaram

                    Hi ,
                    main.moc file is not generating.

                    D Offline
                    D Offline
                    Devopia53
                    wrote on last edited by
                    #10

                    @yuvaram

                    If so, compile it with Network Download Example, which is officially available from Qt.

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Stonge357
                      Banned
                      wrote on last edited by
                      #11
                      This post is deleted!
                      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