undefined reference to ‘vtable for myClass’
I have this undefined reference to ‘vtable for myClass’ problem. Why is it so?
I have a header file myClass.h which contains a slot function
- #ifndef MYCLASS_H
- #define MYCLASS_H
- #include <QObject>
- #include "qdebug.h"
- {
- Q_OBJECT
- public slots:
- void cppSlot(int number);
- };
- #endif // MYCLASS_H
A cpp file myClass.cpp
- #include "myclass.h"
- void myClass::cppSlot(int number) {
- qDebug() << "Called the C++ slot with" << number;
- }
with main file main.cpp
- #include <QtGui/QApplication>
- #include "qmlapplicationviewer.h"
- #include "QDeclarativeContext"
- #include "myclass.h"
- int main(int argc, char *argv[])
- {
- QmlApplicationViewer viewer;
- myClass MyClass;
- viewer.rootContext()->setContextProperty("myObject", &MyClass);
- viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
- viewer.showExpanded();
- return app.exec();
- }
I have also spcific the header and cpp file in my .pro file.
- # Add more folders to ship with the application, here
- folder_01.source = qml/test1
- folder_01.target = qml
- DEPLOYMENTFOLDERS = folder_01
- # Additional import path used to resolve QML modules in Creator's code model
- QML_IMPORT_PATH =
- symbian:TARGET.UID3 = 0xE6EDC966
- # Allow network access on Symbian
- symbian:TARGET.CAPABILITY += NetworkServices
- # Define QMLJSDEBUGGER to allow debugging of QML in debug builds
- # (This might significantly increase build time)
- # DEFINES += QMLJSDEBUGGER
- # If your application uses the Qt Mobility libraries, uncomment
- # the following lines and add the respective components to the
- # MOBILITY variable.
- # CONFIG += mobility
- # MOBILITY +=
- # The .cpp file which was generated for your project. Feel free to hack it.
- SOURCES += main.cpp \
- myclass.cpp
- # Please do not modify the following two lines. Required for deployment.
- include(qmlapplicationviewer/qmlapplicationviewer.pri)
- qtcAddDeployment()
- HEADERS += \
- myclass.h
5 replies
Hi koahnig,
The error message is as follows:
- debug/main.o: In function `myClass':
- C:\Laptop\Dropbox\Qt\examples\test1-build-desktop/../test1//myclass.h:7: undefined reference to `vtable for myClass'
- debug/main.o: In function `~myClass':
- C:\Laptop\Dropbox\Qt\examples\test1-build-desktop/../test1//myclass.h:7: undefined reference to `vtable for myClass'
- collect2: ld returned 1 exit status
- mingw32-make[1]: *** [debug\test1.exe] Error 1
- mingw32-make: *** [debug] Error 2
- The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
- Error while building project test1 (target: Desktop)
- When executing build step 'Make'
http://doc.qt.nokia.com/4.7/debug.html#common-bugs
(moc wasn’t run on your header, and/or the resulting cpp wasn’t linked in. rerun qmake)
Hi Guys,
Thanks for your help, I have moc and I have added
- HEADERS += \
- myclass.h
- SOURCES += main.cpp \
- myclass.cpp
in my .pro file. I found my mistake, I must also add
- CONFIG += qt
It works now, even though I don’t know why. =)
You must log in to post a reply. Not a member yet? Register here!



