当前位置:网站首页>QT笔记——Q_INVOKABLE了解
QT笔记——Q_INVOKABLE了解
2022-08-04 14:50:00 【旧街凉风°】
Q_INVOKABLE
是 QT 中的一个宏
Q_ARG()
Q_RETURN_ARG()
转化为下面:
#define Q_ARG(type, data) QArgument<type >(#type, data)
#define Q_RETURN_ARG(type, data) QReturnArgument<type >(#type, data)
class QMetaObjectTest : public QWidget
{
Q_OBJECT
public:
Q_INVOKABLE void setStr(QString str) {
m_str = str; }
Q_INVOKABLE QString getStr() const {
return m_str; }
private:
QString m_str;
main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMetaObjectTest test;
QMetaObject::invokeMethod(&test, "setStr", Qt::DirectConnection, Q_ARG(QString, "Str"));
QString str;
QMetaObject::invokeMethod(&test, "getStr", Qt::DirectConnection, Q_RETURN_ARG(QString,str));
qDebug() << "str:" << str;
return a.exec();
}
结果:
解释:
invokeMethod 参数,第一个:对象指针,第二个:方法的名字,第三个:连接的方式,第四个:参数的类型 和 赋予的值
参考博客:
Q_INVOKABLE讲解
边栏推荐
- Qt的QItemDelegate使用
- 代码随想录笔记_动态规划_1049最后一块石头的重量II
- leetcode: 253. How many meeting rooms are required at least
- Hangzhou Electric School Competition (Counter Attack Index)
- [Opportunity Enlightenment-60]: "Soldiers, Stupid Ways"-1- Opening: "Death" and "Life" are the way of heaven
- 期货开户之前要谈好最低手续费和交返
- How to automatically renew the token after it expires?
- 【Today in History】August 4: First female Turing Award winner; NVIDIA acquires MediaQ; first Cybersecurity Challenge completed
- leetcode: 251. Expanding 2D Vectors
- 16. Learn MySQL Regular Expressions
猜你喜欢
leetcode:250. 统计同值子树
Sum of four squares, laser bombs
[The Art of Hardware Architecture] Study Notes (1) The World of Metastability
X-ray grazing incidence focusing mirror
FRED应用:毛细管电泳系统
【历史上的今天】8 月 4 日:第一位图灵奖女性得主;NVIDIA 收购 MediaQ;首届网络安全挑战大赛完成
Almost all known protein structures in the world are open sourced by DeepMind
leetcode: 255 Verify preorder traversal sequence binary search tree
代码随想录笔记_动态规划_1049最后一块石头的重量II
MySQL优化学习笔记
随机推荐
【问题解决】QT更新组件出现 “要继续此操作,至少需要一个有效且已启用的储存库”
C# 判断文件编码
License server system does not support this version of this feature
Crawler - action chain, xpath, coding platform use
F. Jinyu and its outer matrix (construction)
eNSP-小型网络拓扑(DNS、DHCP、网站服务器、无线路由器)
leetcode: 251. Expanding 2D Vectors
leetcode:259. 较小的三数之和
Resharper 如何把类里的类移动到其他文件
聊聊与苹果审核员的爱恨情仇
OAID是什么
uni-app 从零开始-生命周期(二)
leetcode:255 验证前序遍历序列二叉搜索树
I love Tanabata hahaha
How to automatically renew the token after it expires?
杭电校赛(ACM组队安排)
[The Art of Hardware Architecture] Study Notes (1) The World of Metastability
企业级优化
Basic Introduction for PLSQL
程序猿七夕礼物-如何30分钟给女朋友快速搭建专属语聊房