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. Transformer.cpp:10: error: undefined reference to `vtable for Transformer'
Qt 6.11 is out! See what's new in the release blog

Transformer.cpp:10: error: undefined reference to `vtable for Transformer'

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 5.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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi, people!
    I'm quite a novice in Qt programing, but I have fine background in c++.
    Currently, I'm trying to create one small program, with 3 classes. Two of them inherit directly QObject, but with one of them (Transformer), I have a problem with constructor:

    @Transformer::Transformer (QObject * parent) : QObject (parent)
    {
    ...
    }@

    When I try to compile all project, linker returns the error from the title.

    The funny thing is, when I copy only this class (ie. transformer.h and transformer.cpp) and main.cpp to some tmp folder, compilation is done without any error.

    Any ideas?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      What does your *.pro file look like? Did you use the Q_OBJECT macro in the declaration of the QObject derived classes? Did moc run? Were the sources generated by moc compiled and linked into the executable?

      Edit:
      By the way: this is a FAQ. Did you search for others asking the same question before posting?

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I've been looking for others with same problems. One proposed solution was to have virtual destructor. I've tried this, but without any result.

        This is .pro for problematic project:
        @######################################################################

        Automatically generated by qmake (2.01a) Tue Dec 21 10:32:26 2010

        ######################################################################

        TEMPLATE = app
        TARGET =
        DEPENDPATH += .
        INCLUDEPATH += .

        Input

        HEADERS += mainprogram.h transformer.h wizard.h
        FORMS += wizard.ui
        SOURCES += main.cpp mainprogram.cpp transformer.cpp wizard.cpp@

        The test project (the one that compiled) have this .pro file:
        @######################################################################

        Automatically generated by qmake (2.01a) Sun Jan 16 21:12:45 2011

        ######################################################################

        TEMPLATE = app
        TARGET =
        DEPENDPATH += .
        INCLUDEPATH += .

        Input

        HEADERS += transformer.h
        SOURCES += main.cpp transformer.cpp@

        There is Q_OBJECT macro at the beginning of Transformer class.

        I Tried with „make clean“ and make again, with no results.
        I don't understand what have happened, but, when I deleted every auto-generated file, including deleting .pro file and Makefile, „qmake -project“ created same .pro file; but then compilation went OK. I guess there was some problem in Makefile, but I didn't save previous one.

        I'm sorry if I've raised topic for nothing, but I'm still confused with this problem (even though the problem had gone now).

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Sometimes you have to re-run qmake to catch up changes.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            I see. Thanks.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dusktreader
              wrote on last edited by
              #6

              [quote author="Volker" date="1295213704"]Sometimes you have to re-run qmake to catch up changes.[/quote]

              This is probably the correct solution. I've done this several times myself. The standard make commands ( make, make clean, etc ) don't remake the MOC objects. Running qmake rebuilds the MOC objects for your code (since it inherits QObject), and then when you run a make, it is able to properly link to the MOC objects.

              “Machines take me by surprise with great frequency.” -- Alan Mathison Turing

              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
              • Unsolved