Qt - 编译器无法识别"连接"

thn*_*tls 8 qt qt4

我在Qt 4.7工作,我有一部分带信号和插槽的代码.它设置正常,即:

#include <QObject>

//Earlier code...
connect(my_thread, SIGNAL(started()), other_thread, SLOT(process()));
connect(my_thread, SIGNAL(finished()), third_thread, SLOT(some_slot()));
//Later code...
Run Code Online (Sandbox Code Playgroud)

但是,当我构建它时,每个语句都会出现错误,说"C3861:'connect':未找到标识符"是否有人有任何想法为什么会这样?谢谢!

Zla*_*mir 18

如果在不属于QObject派生类的代码中使用connect,则在connect之前使用connect QObject::,因此代码将变为:

//Earlier code...
QObject::connect(my_thread, SIGNAL(started()), other_thread, SLOT(process()));
Run Code Online (Sandbox Code Playgroud)

LE:基本上你调用静态连接方法,当你不在QObject(或QObject派生类)的范围内时,你需要完全指定你想要调用的连接,否则编译器找不到它(或者它可能在当前范围内找到错误的连接)