对"vtable for DigitalClock"的未定义引用 - 未定义对"DigitalClock::staticMetaObject"的引用 - Qt
undefined reference to `vtable for DigitalClock' - undefined reference to `DigitalClock::staticMetaObject' - Qt
anisha@linux-dopx:~/Desktop/notes/pomodoro> ls
timer.cpp
anisha@linux-dopx:~/Desktop/notes/pomodoro> qmake -project
anisha@linux-dopx:~/Desktop/notes/pomodoro> qmake
anisha@linux-dopx:~/Desktop/notes/pomodoro> make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../qtsdk-2010.05/qt/mkspecs/linux-g++-64 -I. -I../../../qtsdk-2010.05/qt/include/QtCore -I../../../qtsdk-2010.05/qt/include/QtGui -I../../../qtsdk-2010.05/qt/include -I. -I. -o timer.o timer.cpp
g++ -m64 -Wl,-O1 -Wl,-rpath,/home/anisha/qtsdk-2010.05/qt/lib -o pomodoro timer.o -L/home/anisha/qtsdk-2010.05/qt/lib -lQtGui -L/home/anisha/qtsdk-2010.05/qt/lib -L/usr/X11R6/lib64 -lQtCore -lpthread
timer.o: In function `DigitalClock::DigitalClock(QWidget*)':
timer.cpp:(.text+0x151): undefined reference to `vtable for DigitalClock'
timer.cpp:(.text+0x159): undefined reference to `vtable for DigitalClock'
timer.cpp:(.text+0x1bc): undefined reference to `DigitalClock::staticMetaObject'
timer.o: In function `main':
timer.cpp:(.text+0x2c0): undefined reference to `vtable for DigitalClock'
timer.cpp:(.text+0x2c9): undefined reference to `vtable for DigitalClock'
timer.cpp:(.text+0x30f): undefined reference to `vtable for DigitalClock'
timer.cpp:(.text+0x318): undefined reference to `vtable for DigitalClock'
collect2: ld returned 1 exit status
make: *** [pomodoro] Error 1
我 pomodoro.pro:
######################################################################
# Automatically generated by qmake (2.01a) Tue Feb 14 10:32:09 2012
######################################################################
TEMPLATE = app
TARGET = timer
DEPENDPATH += .
INCLUDEPATH += .
# Input
SOURCES += timer.cpp
我的计时器.cpp:
#include <QLCDNumber>
#include <QtGui>
#include <QApplication>
class DigitalClock : public QLCDNumber
{
Q_OBJECT
public:
DigitalClock (QWidget *parent = 0);
private slots:
void showTime();
};
DigitalClock :: DigitalClock (QWidget *parent) : QLCDNumber (parent)
{
setSegmentStyle(Filled);
QTimer *timer = new QTimer(this);
connect (timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start (1000);
showTime();
setWindowTitle (tr ("Digital Clock"));
resize (150, 60);
}
void DigitalClock :: showTime()
{
QTime time = QTime::currentTime();
QString text = time.toString("hh:mm");
if ((time.second() % 2) == 0)
text[2] = ' ';
display(text);
}
int main (int argc, char *argv[])
{
QApplication app(argc, argv);
DigitalClock clock;
clock.show();
return app.exec();
}
Put
class DigitalClock : public QLCDNumber
{
Q_OBJECT
public:
DigitalClock (QWidget *parent = 0);
private slots:
void showTime();
};
在单独的头文件中,并将其包含在 CPP 中。不要忘记像这样将头文件名放在项目文件中
标头 += \ 数字时钟.h
宏Q_OBJECT
不会在一个文件中工作。希望对您有所帮助。
此错误主要是因为您可能给出了错误的引用。
- 检查您是否添加了程序中所需的所有标头
- 检查 pri 文件
- 检查您是否尝试为具有单例对象的类创建对象
即,如果您创建了一个单例对象,则不允许创建对象。例:
//JSONDataManager class having singleton object
JSONDataManager* JSONDataManager::instance = 0;
JSONDataManager* JSONDataManager::Instance() {
if (instance == 0) {
instance = new JSONDataManager;
}
return instance;
}
//You can access its members as follows
JSONDataManager::Instance()->method();
//You cannot do as follows
JSONDataManager jsonManager;
相关文章:
- 编译C++时未定义的引用
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 对 Scalar ::Scalar() 的未定义引用
- 已定义函数时出现 G++ "未定义的引用"错误
- 链接 cmake 时出现未定义的引用错误
- 对复制 CTOR 和 CTOR 的未定义引用
- 错误:未定义对'oboe::AudioStreamBuilder::openStream(oboe::AudioStream**)'的引用
- 右值引用未定义的行为
- 对"vtable for DigitalClock"的未定义引用 - 未定义对"DigitalClock::staticMetaObject"的引用 - Qt
- 函数类型到函数类型的引用:未定义的引用
- avcodec_alloc_context引用未定义,但ffmpeg链接顺序正确
- 从c++调用Fortran子程序,链接时引用未定义
- 枚举引用未定义,但位于包含的头文件中