gpt4 book ai didi

c++ - QFileSystemWatcher Unresolved external

转载 作者:行者123 更新时间:2023-11-28 05:07:18 27 4
gpt4 key购买 nike

我正在摆弄 QFileSystemWatcher,跟随 this example .但是在编译时出现 Unresolved external symbol 错误。这是我的代码:

#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:错误 LNK2001:未解析的外部符号“public:virtual struct QMetaObject const * __cdecl MyClass::metaObject(void)const”(?metaObject@MyClass@@UEBAPEBUQMetaObject@@XZ)

main.obj:错误 LNK2001:未解析的外部符号“public:virtual void * __cdecl MyClass::qt_metacast(char const *)”(?qt_metacast@MyClass@@UEAAPEAXPEBD@Z)

main.obj:错误 LNK2001:未解析的外部符号“public: virtual int __cdecl MyClass::qt_metacall(enum QMetaObject::Call,int,void * *)”(?qt_metacall@MyClass@@UEAAHW4Call@QMetaObject @@HPEAPEAX@Z)

debug\FileSystemWatcherTest.exe: fatal error LNK1120:3 个 Unresolved external 问题

我做错了什么?

最佳答案

尝试将 MyClass 定义放在单独的 .h 文件中

关于c++ - QFileSystemWatcher Unresolved external ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44390106/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com