我最近需要添加一個信號到一個類,所以我改變了類從QObject繼承,並將Q_OBJECT宏添加到類定義中。因爲這樣做,我得到「信號未定義的引用錯誤‘虛函數表的CLICommand’」下面的班線錯誤:Qt「信號未定義的參考錯誤」從QObject繼承後
// File clicommand.h
#include <QString>
#include <QStringList>
#include <QTcpSocket>
#include "telnetthread.h"
class CLICommand : public QObject
{
Q_OBJECT
public:
CLICommand(TelnetThread *parentTelnetThread);
signals:
void signal_shutdown_request();
private:
TelnetThread *m_parentTelnetThread;
和第二誤差「信號未定義的引用爲‘虛函數表的CLICommand’錯誤」下面的線(intializing成員變量):
// File clicommand.cpp
#include <QDebug>
#include <QTcpSocket>
#include <QTextStream>
#include "version.h"
#include "clicommand.h"
#include "telnetthread.h"
#include "logger.h"
CLICommand::CLICommand(TelnetThread *parentTelnetThread)
: m_parentTelnetThread(parentTelnetThread)
{
}
,只是這裏是我發射該信號。了,emit行生成錯誤未定義的參考`CLICommand :: signal_shutdown_request()」:
// file shutdown_clicommand.cpp
#include <QIODevice>
#include "clicommand.h"
#include "logger.h"
#include "version.h"
void CLICommand::execute_shutdown(const QStringList &commandLineFragments)
{
emit signal_shutdown_request();
}
我讀了一堆關於這個主題的帖子,但似乎都不適用。我什至試圖乾淨/ rebuildall。我不使用升壓或其他庫...只是QT 5
有人能告訴我我做錯了什麼嗎?
解決方案:在QT Creator中,右鍵單擊項目,選擇RUN QMAKE,然後重新生成所有。關於運行重建ALL的其他帖子是不正確的......在它自己不會運行qmake。
往常,感謝+1 –
也許使用Qt Creator的時候明確地重新運行'qmake'最簡單的方法就是直接去構建和刪除'Makefile'。然後,在下一個「全部構建」動作中,Qt Creator重新生成它,這樣「Q_OBJECT」變化相關的鏈接錯誤消失。 – maxschlepzig