【发布时间】:2019-05-15 09:48:14
【问题描述】:
我在控制台应用程序中创建了使用 QTimer 的最简单的类。
编译器生成一个错误:未定义对“vtable for Timer”的引用。其中指带构造函数的字符串:Timer() {}
我在这个网站上找到了很多关于这个问题的建议,例如:
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
所有的答案都归结为清除项目,然后运行 QMake 并重建项目。 不幸的是,这一切都没有帮助我。 我也试过删除“Debug”文件夹,做了以上操作后,结果是一样的。
我在实际的多文件程序中不断积极地使用信号槽技术,从来没有遇到过这样的问题。
请分享你的想法!
#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
【问题讨论】:
标签: c++ qt connect signals-slots