Q_INVOKABLE与invokeMethod

阅读 55

2022-01-20

Q_INVOKABLE

#define Q_INVOKABLE

该宏定义在$QTDIR/src/corelib/kernel/qobjectdefs.h 中,目的在于让moc识别。

使用Q_INVOKABLE来修饰成员函数,目的在于被修饰的成员函数能够被元对象系统所唤起。

QMetaObject::invokeMethod

invokeMethod的用法为,尝试调用对象obj的方法member(注意member可以为信号或者是槽),如何member可以被调用,则返回真,否则返回假。QMetaObject::invokeMethod可以是异步调用,也可以是同步调用。这取决与它的连接方式Qt::ConnectionType type。如果type为Qt::DirectConnection,则为同步调用,若为Qt::QueuedConnection,则为异步调用。

QMetaObject::invokeMethod(ptr_bus, "Uninit", Qt::BlockingQueuedConnection);

精彩评论(0)

0 0 举报