9

我正在使用 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...

但是,当我构建它时,每个语句都会出现错误,说“C3861:'连接':找不到标识符”有没有人知道为什么会这样?谢谢!

4

1 回答 1

21

如果您在不属于QObject派生类的代码中使用连接,请在连接之前加上QObject::,因此代码将变为:

//Earlier code...
QObject::connect(my_thread, SIGNAL(started()), other_thread, SLOT(process()));

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

于 2013-09-10T20:04:23.473 回答