InvokeMethod 不适用于 SLOT(...),但适用于 conts char *

InvokeMethod doesn't work with SLOT(...), but works with conts char *

本文关键字:适用于 conts char 不适用 SLOT InvokeMethod      更新时间:2023-10-16

我有下一个类:FoxComFoxComCircle。在FoxCom中,我有下一个代码:

...
public slots:
 void bytesWrite(QByteArray bytes, qint32 requestedTimeout = -1);
...
FoxComCircle * circle;
...
void FoxCom::bytesWrite(QByteArray bytes, qint32 requestedTimeout)
{
    QMetaObject::invokeMethod(circle,
                              //SLOT(bytesToWrite(QByteArray,qint32)),
                              "bytesToWrite",
                              Qt::QueuedConnection,
                              Q_ARG(QByteArray, bytes),
                              Q_ARG(qint32, requestedTimeout));
}

并且在FoxComCircle:中

...
public slots:
  void bytesToWrite(QByteArray bytes, qint32 requestedTimeout);
...
void FoxComCircle::bytesToWrite(QByteArray bytes, qint32 requestedTimeout)
{
   //some stinky code here
}

还有下一个行为:当我注释"bytesToWrite",并使用SLOT(bytesToWrite(QByteArray,qint32)),时,当调用FoxCom::bytesWrite时,我在输出控制台中有下一条消息:

QMetaObject::invokeMethod: No such method FoxComCircle::1bytesToWrite(QByteArray

,qint32)(QByteArray,qint32)

但是,当我直接使用constchar*名称时(如上面的代码所示),它是有效的。

我做错什么了吗?

p.S.CCD_ 8和CCD_。

提前谢谢。

根据Qt文档中的QMetaObject::invokeMethod描述:

调用对象obj…上的成员(信号或插槽名称

因此,您必须提供插槽的名称,而不是完整的签名。这是一致的,因为您提供插槽的参数作为invokeMethod函数的以下参数。