我从我的线程中调用以下内容:
QMetaObject::invokeMethod(pProcessor,
"doTask",
Qt::QueuedConnection,
Q_RETURN_ARG(quint32, taskId),
Q_ARG(quint64, objId),
Q_ARG(quint8, intId),
Q_ARG(QString, name),
Q_ARG(QString, comment)
);
Run Code Online (Sandbox Code Playgroud)
但无论我做什么,它都会失败.如果我取出Q_RETURN_ARG(quint32,taskId),则调用该方法,但我需要taskId,这是我无法获得的.任何帮助深表感谢.
Aru*_*mar 24
我假设你想从非所有者线程调用一个对象的方法,并希望得到返回值.为此,请使用"Qt :: BlockingQueuedConnection"作为连接类型.
quint32 taskId; // Declare taskId.
qRegisterMetaType<quint32>("quint32");
QMetaObject::invokeMethod(pProcessor,
"doTask",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(quint32, taskId),
Q_ARG(quint64, objId),
Q_ARG(quint8, intId),
Q_ARG(QString, name),
Q_ARG(QString, comment)
);
Run Code Online (Sandbox Code Playgroud)
如果你的方法返回非标准的返回类型,你必须在调用QMetaObject :: invokeMethod(...)之前注册你的类型.请参阅http://qt-project.org/doc/qt-5.0/qtcore/qmetatype.html#qRegisterMetaType.