我擺弄QFileSystemWatcher
,跟在this example後面。但編譯時,我得到一個無法解析的外部符號錯誤。 這裏是我的代碼:QFileSystemWatcher無法解析的外部
#include <QCoreApplication>
#include <QFileSystemWatcher>
#include <QObject>
#include <iostream>
class MyClass : public QObject
{
Q_OBJECT
public:
MyClass(QObject* parent = nullptr) : QObject(parent){}
public slots:
void on_dir_change(const QString& path)
{
std::cout << "folder modified: (" << path.toStdString() << ")" <<
std::endl;
}
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFileSystemWatcher watcher;
watcher.addPath("C:/test");
MyClass* mc = new MyClass();
QObject::connect(&watcher, SIGNAL(directoryChanged(QString)), mc,
SLOT(on_dir_change(QString)));
return a.exec();
}
其中關於編制產生以下錯誤信息:
main.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl MyClass::metaObject(void)const " ([email protected]@@[email protected]@XZ)
main.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl MyClass::qt_metacast(char const *)" ([email protected]@@[email protected])
main.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl MyClass::qt_metacall(enum QMetaObject::Call,int,void * *)" ([email protected]@@[email protected]@@[email protected])
debug\FileSystemWatcherTest.exe : fatal error LNK1120: 3 unresolved externals
我在做什麼錯?
您可以提供錯誤消息嗎?哪個功能無法解決? –
你還沒有實現'MyClass :: MyClass(class QObject *)'。 –
我實現了構造函數(請參閱編輯),但仍然出錯。我執行錯了嗎? – DenverCoder21