Qt: undefined reference to `vtable for - c++

When I try to compile my program I get the error
obj/backgroundWorker.o: In function `BackgroundWorker':
.../backgroundWorker.cpp:6: undefined reference to `vtable for BackgroundWorker'
obj/backgroundWorker.o: In function `~BackgroundWorker':
.../backgroundWorker.cpp:14: undefined reference to `vtable for BackgroundWorker'
I already found numerous reasons for this error, but so far, I couldn't
solve the problem in my code:
backgroundWorker.hpp
#include <QObject>
#include <QPushButton>
class BackgroundWorker : public QWidget{
Q_OBJECT
public:
explicit BackgroundWorker();
~BackgroundWorker();
private slots:
void start();
private:
QPushButton* mStartButton;
};
backgroundWorker.cpp
#include <iostream>
#include "getInput.hpp"
#include "backgroundWorker.hpp"
#include "LIF_network.hpp"
BackgroundWorker::BackgroundWorker(){
mStartButton = new QPushButton("Start",this);
mStartButton->setGeometry(QRect(QPoint(100,100),QSize(200,50)));
connect(mStartButton, SIGNAL(released()), this, SLOT(start()));
}
BackgroundWorker::~BackgroundWorker(){
delete mStartButton;
}
void BackgroundWorker::start(){
//stuff not related to qt
}
main.cpp
#include <QApplication>
#include "backgroundWorker.hpp"
int main(int argc, char *argv[]){
QApplication a(argc, argv);
BackgroundWorker bw;
return a.exec();
}
** .pro file**
CONFIG += qt debug c++11
QT += widgets
QMAKE_CC = clang++
QMAKE_CXX = clang++
QMAKE_CXXFLAGS += -Wall -Werror -O3
Headers += image.hpp \
getInput.hpp \
LIF_network.hpp \
backgroundWorker.hpp \
SOURCES += main.cpp \
image.cpp \
getInput.cpp \
LIF_network.cpp \
backgroundWorker.cpp \
OBJECTS_DIR = ./obj

As Frank Osterfeld mentioned in the comment the proper name for the variable is upper case HEADERS. And it should contain the list of all headers that have Q_OBJECT macro in them
This is required because qmake needs to know the list of header files to feed to the moc.

Related

Undefined reference error when linking dynamic and static libraries consequently

I have a QT project with 4 subprojects with the following names: exec (executable), sharedlib (dynamic library), sharedlib2 (other one dynamic library) and staticlib. All this is linked consequently as follows:
exec->sharedlib2->sharedlib->staticlib
In the static library is defined Staticlib class.
Now, when compiling all of this, I'm getting undefined reference error when trying to use that class (in exec project, main.cpp):
/home/user/temp/libproj/libproj/exec/main.cpp:9: error: undefined reference to `Staticlib::Staticlib()'
What am I doing wrong?
staticlib.h:
#ifndef STATICLIB_H
#define STATICLIB_H
#include <QDebug>
class Staticlib
{
public:
Staticlib();
void debugprint();
};
#endif // STATICLIB_H
sharedlib.pro:
QMAKE_LFLAGS += -Wl,--whole-archive,--allow-multiple-definition
LIBS += -L$$OUT_PWD/../staticlib/
LIBS += -lstaticlib
sharedlib2.pro:
LIBS += -L$$OUT_PWD/../sharedlib/
LIBS += -lsharedlib
exec.pro:
INCLUDEPATH += $$PWD/../staticlib
#doesnt work
LIBS += -L$$OUT_PWD/../sharedlib2
LIBS += -lsharedlib2
#works well
#//LIBS += -L$$OUT_PWD/../sharedlib/
#//LIBS += -lsharedlib
exec, main.cpp:
#include <QCoreApplication>
#include "staticlib.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Staticlib statlib;
statlib.debugprint();
return a.exec();
}
staticlib.pro
QT -= gui
TEMPLATE = lib
CONFIG += staticlib
CONFIG += c++17
SOURCES += \
staticlib.cpp
HEADERS += \
staticlib.h
staticlib.cpp
#include "staticlib.h"
#include <QDebug>
Staticlib::Staticlib()
{
}
void Staticlib::debugprint()
{
qDebug() << "Staticlib::debugprint()";
}

ERROR that looks so main.cpp:(.text.startup+0xd6): undefined reference to `vtable for Counter'?

I have naturally trivial question as I mean: we press button --> counter increases, counter increases --> QLabel's value is renewed. I caught strange error and don't want to do. I'm not dummy in C++ but in QT I am. It's my first and most trivial application in it.
Some answers there (on Stack Overflow) advised to add virtual constructor. It has no effect.
I tried to rewrite signals and slots to new qt5 style but there were another problems, I was too lazy to fix them, was it (rewriting, not laziness :) ) a good way, maybe problem is really with versions?
I just haven't tried to reinstall QT or install Qt4, maybe problem is in it?
about versions:
$ qmake --version
responds:
QMake version 3.0
Using Qt version 5.5.1 in /usr/lib/x86_64-linux-gnu
conn.pro:
TEMPLATE = app
QT += core gui
TARGET = conn
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp
main.cpp:
#include <QApplication>
#include <QLabel>
#include <QPushButton>
#include <QObject>
class Counter : public QObject {
Q_OBJECT
private:
double i_;
public:
virtual ~Counter()
{
}
Counter() : QObject(), i_(0)
{
}
public slots:
void slot_incCounter();
signals:
void goodbye(){}
void counterChanged(double){}
};
void Counter::slot_incCounter() {
emit counterChanged(++i_);
if (i_ == 5) {
emit goodbye();
}
}
int main(int argc, char* argv[]) {
QApplication my_app(argc, argv);
QLabel label1("label i created");
label1.show();
QPushButton button1("press me");
button1.show();
Counter counter1;
QObject::connect(&button1, SIGNAL(clicked()),
&counter1, SLOT(slot_incCounter()));
QObject::connect(&counter1, SIGNAL(counterChanged(double a)),
&label1, SLOT(setNum(double a)));
QObject::connect(&counter1, SIGNAL(goodbye()),
&my_app, SLOT(quit()));
return my_app.exec();
}
Try to run it:
qmake && make && ./conn
So I see in console:
g++ -m64 -Wl,-O1 -o conn main.o -L/usr/X11R6/lib64 -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
main.o: In function `main':
main.cpp:(.text.startup+0xd6): undefined reference to `vtable for Counter'
collect2: error: ld returned 1 exit status
Makefile:144: recipe for target 'conn' failed
make`:` *** [conn] Error 1
What should I do?
Qt uses the meta object compiler (moc) to enable e.g. signal and slots. By default it works perfectly if the Q_OBJECT macro is in a header file. So the easiest would be you put Counter into it's own header/implementation file, rerun qmake and make. (That's by the way good practice...)
If you want to stick with a single main.cpp file you need to tell the moc explicitly that this file contains macros moc needs to parse. You do this with the following line at the very end of main.cpp:
#include "main.moc"
Then also rerun qmake and make.
Please keep in mind that the manually including a moc-include directive is not the best choice. So better split your C++ classes into separate files right from the beginning...
Thank you very much! Your answer was full, useful and making all more obvious.
Solution was:
1. Move class Counter to Counter.h
Since this moment the message about vtable disappeared. Appeared messages that goodbye() and Counter::counterChanged(double) have multiple definition. The first definition was mine in Counter.cpp (WRONG WAY). The second was in moc_Counter.cpp, generated by MOC utility. So:
2. Remove definitions (my empty definitions) of signal functions, because moc makes its own in file moc_Counter.cpp:
// SIGNAL 0
void Counter::goodbye()
{
QMetaObject::activate(this, &staticMetaObject, 0, Q_NULLPTR);
}
// SIGNAL 1
void Counter::counterChanged(double _t1)
{
void *_a[] = { Q_NULLPTR, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 1, _a);
}
and they cause a problem of multiple definition.
Summing it up, working code:
main.cpp:
#include <QApplication>
#include "Counter.h"
int main(int argc, char* argv[]) {
QApplication my_app(argc, argv);
QLabel label1("1");
label1.show();
QPushButton button1("press me");
button1.show();
Counter counter1;
QObject::connect(&button1, SIGNAL(clicked()),
&counter1, SLOT(slot_incCounter()));
QObject::connect(&counter1, SIGNAL(counterChanged(double)),
&label1, SLOT(setNum(double)));
QObject::connect(&counter1, SIGNAL(goodbye()),
&my_app, SLOT(quit()));
return my_app.exec();
}
void Counter::slot_incCounter() {
emit counterChanged(++i_);
if (i_ == 5) {
emit goodbye();
}
}
Counter.h:
#ifndef COUNTER_H
#define COUNTER_H
#include <QLabel>
#include <QPushButton>
#include <QObject>
class Counter : public QObject {
Q_OBJECT
private:
double i_;
public:
virtual ~Counter()
{
}
Counter() : QObject()
{
}
public slots:
void slot_incCounter();
signals:
void goodbye();
void counterChanged(double);
};
#endif // COUNTER_H
Counter.cpp:
#include "Counter.h"
Thank you, you're great!

Qt Signal/Slot configuration [duplicate]

I have been struggling for a while with an issue on Qt.
Here is my code:
hexbutton.h:
#ifndef HEXBUTTON_H
#define HEXBUTTON_H
#include <QPushButton>
#include <QWidget>
#include <QIcon>
class HexButton : public QPushButton
{
Q_OBJECT
public:
HexButton(QWidget *parent, QIcon &icon, int i, int j);
public slots:
void changeIcon();
};
#endif // HEXBUTTON_H
Hexbutton.cpp:
#include "hexbutton.h"
HexButton::HexButton(QWidget *parent, QIcon &icon, int i , int j) : QPushButton(parent){
//setFlat(true);
setIcon(icon);
setGeometry((i*40)+((j*40)/2), j*40, 40, 40);
}
void HexButton::changeIcon(){
setIcon(QIcon("/Users/jonathanbibas/Documents/Workspace Qt/Test/hexagon.gif"));
}
MyWindow.h:
#ifndef MYWINDOW_H
#define MYWINDOW_H
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QLCDNumber>
#include <QSlider>
#include <QProgressBar>
#include "hexbutton.h"
class MyWindow : public QWidget
{
public:
MyWindow();
~MyWindow();
private:
HexButton * myButtons[11][11];
};
#endif // MYWINDOW_H
MyWindow.cpp:
#include "MyWindow.h"
#include <QColor>
#include <QIcon>
MyWindow::MyWindow() : QWidget() {
setFixedSize(740, 440);
QIcon icon = QIcon("/Users/jonathanbibas/Documents/Workspace Qt/Test/whitehexagon.png");
for(int i =0 ; i < 11 ; i ++){
for(int j =0 ; j < 11 ; j ++){
myButtons[i][j] = new HexButton(this, icon, i, j);
QObject::connect(myButtons[i][j], SIGNAL(clicked()), myButtons[i][j], SLOT(changeIcon()));
}
}
}
MyWindow::~MyWindow()
{
delete myButtons;
}
And finally, Main.cpp:
#include <QApplication>
#include "MyWindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWindow fenetre;
fenetre.show();
return app.exec();
}
Just in case, here is the Test.pro
SOURCES += \
Main.cpp \
MyWindow.cpp \
hexbutton.cpp
HEADERS += \
MyWindow.h \
hexbutton.h
And I get the 2 errors:
1) symbol(s) not found for architecture x86_64
2) collect2: ld returned 1 exit status
It also says 121 times (11*11):
Object::connect: No such slot QPushButton::changeIcon() in ../Test/MyWindow.cpp:19
and on the compile output it says:
18:22:15: Running build steps for project Test...
18:22:15: Configuration unchanged, skipping qmake step.
18:22:15: Starting: "/usr/bin/make" -w
make: Entering directory `/Users/jonathanbibas/Documents/Workspace Qt/Test-build-desktop-Desktop_Qt_4_8_0_for_GCC__Qt_SDK__Debug'
g++ -c -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/mkspecs/macx-g++ -I../Test -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/lib/QtCore.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/include/QtCore -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/lib/QtGui.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/include/QtGui -I../../../QtSDK/Desktop/Qt/4.8.0/gcc/include -I. -I../Test -I. -F/Users/jonathanbibas/QtSDK/Desktop/Qt/4.8.0/gcc/lib -o hexbutton.o ../Test/hexbutton.cpp
g++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -o Test.app/Contents/MacOS/Test Main.o MyWindow.o hexbutton.o moc_MyWindow.o -F/Users/jonathanbibas/QtSDK/Desktop/Qt/4.8.0/gcc/lib -L/Users/jonathanbibas/QtSDK/Desktop/Qt/4.8.0/gcc/lib -framework QtGui -framework QtCore
Undefined symbols for architecture x86_64:
"vtable for HexButton", referenced from:
HexButton::HexButton(QWidget*, QIcon&, int, int)in hexbutton.o
HexButton::HexButton(QWidget*, QIcon&, int, int)in hexbutton.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [Test.app/Contents/MacOS/Test] Error 1
make: Leaving directory `/Users/jonathanbibas/Documents/Workspace Qt/Test-build-desktop-Desktop_Qt_4_8_0_for_GCC__Qt_SDK__Debug'
18:22:20: The process "/usr/bin/make" exited with code 2.
Error while building project Test (target: Desktop)
When executing build step 'Make'
Apparently the error comes from the Q_OBJECT (needed for the slots definition), but there is something wrong with my code, not with my compiler (because I have when slots are in MainWindow, it works fine).
Thank you for your help!
Faced same problem
undefined refrence error for my signal.
After putting Q_OBJECT macro... vtable errors.
I did this and worked for me
Added Q_OBJECT to file
Cleaned project
Ran qmake
Rebuild
it compiles fine.
Got the same error. I had a private slot declared in a .h file, but I didn't have it defined in my cpp file. I removed my unused slot in both places, and it compiled.
This happened to me when merging Qt code from one platform to another. I just resolved it, after much trial and error, so I'm posting it here since my issue was different. If you are merging new files, you can't just merge the files and the .Pro file and expect that they'll show up in Qt Creator for compilation. Notice your new files aren't actually being displayed in the IDE under your folders. I overlooked this, and was just looking at the folder structure and .Pro file. Once I manually added all of the files in Qt, it compiled fine. Here is how I figured this out:
Right click on the vague "symbol(s) not found for architecture x86_64" error, and select Compiled Output
At the bottom it will show what method(s) it can't find. Find what file(s) those methods are in, and add those headers and class files, by right clicking the folder they should be in the IDE, and selecting "Add Existing File"
Build, or Clean then Build
CONFIG -= x86_64 fixed this problem for me
This can happen, when you forgot the Class-Operator, when defining your function.
H File:
class Globals
{
public:
unsigned int myFunction();
};
CPP File:
unsigned int Globals::myFunction(){return 3;}
I found the answer finally! (for whoever will be interested)
The mistake is that I shouldn't have extended the class QPushButton, to customize my button, but rather, create my own class HexButton extending/inheriting the QWidget class!
Doing so we must add to the button, a QPushButton instance.
Well it then makes:
class HexButton : public QWidget
{
Q_OBJECT
public:
HexButton(QWidget *parent = 0);
public slots:
void changeIcon();
private:
QPushButton *button;
};
Move the slot changeIcon() into HexButton class from MyWindow class.
Normally this happens with Qt because of your build system - it indicates that you're not compiling/linking in the code generated by moc
I'm pretty sure that there's nothing wrong with your code - so the error must be in some setting in qt creator, which I can't really help with as I've not used it much.
If you haven't already, you could try adding an explicit empty destructor declaration to hexbutton.hpp and definition to hexbutton.cpp. It shouldn't be necessary, but I've heard of this making a difference on some quirky compilers/linkers.
try to remove pro.user file and reimport project with any qt 32bit kit.

Unresolved external symbols - Qt creator

I must be missing a basic concept with headers and includes because when I attempt to call even the simplest of a function from a separate source file I get an error:
main.obj:-1: error: LNK2019: unresolved external symbol "void __cdecl
buildDeck(int,int)" (?buildDeck##YAXHH#Z) referenced in function _main
deck.h
#ifndef DECK_H
#define DECK_H
#include <QString>
void buildDeck(int deckSize, int jokers);
struct card
{
QString suit;
QString color;
int rank;
};
#endif // DECK_H
deck.cpp
#include"mainwindow.h"
#include "deck.h"
void buildDeck(int deckSize, int jokers)
{
int blackRed = deckSize-=jokers;
}
main.cpp
#include "mainwindow.h"
#include "deck.h"
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
buildDeck(10,20);
return a.exec();
}
And this gives me an error. However, If I move the function definition from deck.cpp to the bottom of main.cpp, then the application will build.
All of the files are included in the same project, and stored in the same directory.
Other files:
.pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = carddeck
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
deck.cpp
HEADERS += mainwindow.h \
deck.h
FORMS += mainwindow.ui
not sure if you need it, but here's mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <QTextEdit>
#include <QCheckBox>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void runButtonClicked();
private:
Ui::MainWindow *ui;
QPushButton *runButton;
QTextEdit * runText;
QCheckBox * betHearts;
QCheckBox * betDiamonds ;
QCheckBox * betClubs;
QCheckBox * betSpades ;
QCheckBox * betFlush ;
QCheckBox * betAllRed;
QCheckBox * betAllBlack ;
};
#endif // MAINWINDOW_H
It looks like the Makefile was not regenerated when you edited the .pro file.
Run qmake and try again.
You could also check if the deck.cpp is compiled or not; is there a deck.o in the build directory ?
yes, some time Makefile file is not updated while you change .pro file. So you have to run qmake.
Follow this steps:
Right click on project Clean / Build menu -> cleanAll
Right click on project Run qmake / Build menu -> runQmake
Right click on project Build / Build menu -> build
Pro Advice:
I don't know but sometime Qt is not updating Makefile. so i recomanded to all whenever you add/removing any resource in project or if any changes occur in your .pro file, just Run qmake and build your project(Running qmake do manually to update the path of project, which help to find the mainwindow.obj file).

Undefined reference to vtable... Q_OBJECT macro [duplicate]

This question already has answers here:
Qt Linker Error: "undefined reference to vtable" [duplicate]
(9 answers)
Closed 9 years ago.
When I uncomment the Q_OBJECT macro that I need for signal-slot I get a undefined reference to vtable for MyApp error, but without the macro it compiles perfectly but I can't use signals and slots without it. I think I may be doing something stupid wrong, but please try helping because I realy can't find the problem. O and I know my code is untidy and am working on it.
myapp.h:
#ifndef MYAPP_H
#define MYAPP_H
#include <QApplication>
#include <QEvent>
#include <QObject>
#include <QDebug>
class MyApp : public QApplication
{
public:
MyApp( int argc, char** argv );
protected:
bool eventFilter(QObject *object, QEvent *event);
signals:
void focusG();
void focusL();
};
#endif // MYAPP_H
myapp.cpp:
#include "myapp.h"
MyApp::MyApp(int argc, char **argv): QApplication(argc, argv)
{
installEventFilter(this);
}
bool MyApp::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::ApplicationDeactivate)
{
qDebug() << "Focus lost";
//focusL();
}
if (event->type() == QEvent::ApplicationActivate)
{
qDebug() << "Focus gained";
//focusG();
}
return false;
}
main.cpp:
#include <QtGui/QApplication>
#include "qmlapplicationviewer.h"
#include <QObject>
#include <QGraphicsObject>
#include <QTimer>
#include <QVariant>
#include "timecontrol.h"
#include "scorecontrol.h"
#include "Retry.h"
#include <QEvent>
#include "myapp.h"
int main(int argc, char *argv[])
{
//QApplication app(argc, argv);
MyApp app(argc, argv);
QmlApplicationViewer viewer;
viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);
viewer.setMainQmlFile(QLatin1String("qml/Raker/main.qml"));
viewer.showExpanded();
QObject *rootObject = viewer.rootObject();
QTimer *timmer = new QTimer;
timmer->setInterval(1000);
TimeControl *timcon = new TimeControl;
scorecontrol *scorer = new scorecontrol;
Retry *probeer = new Retry;
QObject::connect(timmer, SIGNAL(timeout()), timcon, SLOT(updateTime()));
QObject::connect(timcon, SIGNAL(setTime(QVariant)), rootObject, SLOT(setTime(QVariant)));
QObject::connect(rootObject, SIGNAL(blockClicked(int, int)), scorer, SLOT(checkRight(int, int)));
QObject::connect(scorer, SIGNAL(setScore(QVariant)), rootObject, SLOT(setScore(QVariant)));
QObject::connect(scorer, SIGNAL(setState(QVariant)), rootObject, SLOT(setState(QVariant)));
QObject::connect(rootObject, SIGNAL(start()), probeer, SLOT(Reetry()));
QObject::connect(probeer, SIGNAL(start()), timmer, SLOT(start()));
QObject::connect(probeer, SIGNAL(stop()), timmer, SLOT(stop()));
QObject::connect(probeer, SIGNAL(start(int)), scorer, SLOT(randomNum(int)));
QObject::connect(probeer, SIGNAL(sReset()), timcon, SLOT(reset()));
QObject::connect(probeer, SIGNAL(tReset()), scorer, SLOT(reset()));
QObject::connect(timcon, SIGNAL(timeOut()), scorer, SLOT(reset()));
QObject::connect(timcon, SIGNAL(setState(QVariant)), rootObject, SLOT(setState(QVariant)));
QObject::connect(timcon, SIGNAL(changeFinal()), scorer, SLOT(changeFinal()));
QObject::connect(scorer, SIGNAL(setFinal(QVariant)), rootObject, SLOT(setFinal(QVariant)));
QObject::connect(&app, SIGNAL(focusL()), probeer, SLOT(focusL()));
QObject::connect(&app, SIGNAL(focusG()), probeer, SLOT(focusG()));
return app.exec();
}
BlockToucher.pro:
# Add more folders to ship with the application, here
folder_01.source = qml/Raker
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 = 0x2004b49f
# Smart Installer package's UID
# This UID is from the protected range and therefore the package will
# fail to install if self-signed. By default qmake uses the unprotected
# range value if unprotected UID is defined for the application and
# 0x2002CCCF value if protected UID is given to the application
symbian:DEPLOYMENT.installer_header = 0x2002CCCF
# Allow network access on Symbian
symbian {
#TARGET.CAPABILITY += NetworkServices
vendorinfo = "%{\"Gerhard de Clercq\"}" ":\"Gerhard de Clercq\""
ICON = BlockToucher.svg
}
# 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 \
timecontrol.cpp \
scorecontrol.cpp \
Retry.cpp \
myapp.cpp \
myapplication.cpp
# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
qtcAddDeployment()
HEADERS += \
timecontrol.h \
scorecontrol.h \
Retry.h \
myapp.h \
myapplication.h
OTHER_FILES += \
qtc_packaging/debian_fremantle/rules \
qtc_packaging/debian_fremantle/README \
qtc_packaging/debian_fremantle/copyright \
qtc_packaging/debian_fremantle/control \
qtc_packaging/debian_fremantle/compat \
qtc_packaging/debian_fremantle/changelog
compat \
qtc_packaging/debian_fremantle/changelog
Q_OBJECT is used by the MOC system to produce the code you need for the signals. My best guess would be that you are not included the MOC generated files in your project (the CPP files which it generates).
How you do this greatly depends on your build system (CMake, QMake, AUtomake, MSVC) but you should refer to the tutorial with QMake first.
That is, the undefined reference to vtable is the error I sometimes get when I forget to update my Cmake files and have a Q_OBJECT.
Also, your ctor for MyApp is wrong, the signature must be:
MyApp( int & argc, char** argv );
The & is important should you ever use command-line parameters.
I had same issue when i decided to add Q_OBJECT into my header file.
First try run qmake manually.
If not resolved, so delete build folder and build project again
If building all of the project is a heavy task, so try following steps:
Add a new temp class with QObject as its base class
Double check your header and source file for any mistake using new temp class
Build your project. It should built successfully
Remove your temp class completely (.h and .cpp file and relative lines on .pro file)
Good luck :)