I created the simplest class for working with QTimer in my console application.
The compiler generates an error: Undefined reference to `vtable for Timer'. Whereind refers to the string with constructor: Timer() {}
I found many recommendations on this issue on this site, for example:
Undefined reference to vtable. Trying to compile a Qt project
Qt Linker Error: "undefined reference to vtable"
Q_OBJECT throwing 'undefined reference to vtable' error
All the answers boil down to clearing the project, then running QMake and rebuilding the project. Unfortunately, all this did not help me. I also tried to delete the "Debug" folder, and after doing the above actions - the result is the same.
I constantly and actively use the technique of signals and slots in real multi-file programs, and I have never encountered such problems.
Please share your ideas!
#include <QCoreApplication>
#include <QDebug>
#include <QTimer>
#include <QObject>
class Timer : public QObject {
Q_OBJECT
public:
Timer() {}
virtual ~Timer() {}
public slots:
void someSlot();
};
void Timer::someSlot() {
qDebug() << "someSlot()";
}
int main(int argc, char *argv[])
{
QCoreApplication aa(argc, argv);
QTimer *timer = new QTimer();
Timer *myTimer = new Timer();
QObject::connect(timer, SIGNAL(timeout()), myTimer, SLOT(someSlot()));
timer->start(1500);
return aa.exec();
}
//-----------------------
// pro-file
QT += core
QT -= gui
CONFIG += c++11 c++14
TARGET = test_for_all
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp