当前位置:网站首页>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讲解
边栏推荐
- Cisco-小型网络拓扑(DNS、DHCP、网站服务器、无线路由器)
- C# 将dll打包到程序中
- xampp安装包含的组件有(php,perl,apche,mysql)
- leetcode: 259. Smaller sum of three numbers
- Go 语言快速入门指南: 变量和常量
- Hangzhou Electric School Competition (Counter Attack Index)
- Phasecraft连下两城,助力英国量子技术商业化加速!
- X-ray grazing incidence focusing mirror
- Lixia Action | Kyushu Yunzhang Jinnan: Open source is not a movement for a few people, popularization is the source
- Database recovery
猜你喜欢

用了TCP协议,就一定不会丢包吗?

leetcode:250. 统计同值子树

输入输出流总结

Technology sharing | Description of the electronic fence function in the integrated dispatching system

四平方和,激光炸弹

1401 - Web technology 】 【 introduction to graphical Canvas

IP第十七天笔记

eNSP-小型网络拓扑(DNS、DHCP、网站服务器、无线路由器)

Almost all known protein structures in the world are open sourced by DeepMind
![[The Art of Hardware Architecture] Study Notes (1) The World of Metastability](/img/ac/54e4e13d9df90e96933c69623b770e.png)
[The Art of Hardware Architecture] Study Notes (1) The World of Metastability
随机推荐
在腾讯,我的试用期总结!
C# TextBlock 上标
Nuget 通过 dotnet 命令行发布
华为云 & 达达,帮有情人“一键送达”
宣传海报
token 过期后,如何自动续期?
eNSP-小型网络拓扑(DNS、DHCP、网站服务器、无线路由器)
大众点评搜索相关性技术探索与实践
Google plug-in. Download contents file is automatically deleted after solution
7 天能找到 Go 工作吗?学学 Go 数组和指针试试
输入输出流总结
JCMsuite Application: Oblique Plane Wave Propagation Transmission Through Aperture
【Web技术】1401- 图解 Canvas 入门
苏秋贵:揭秘绿联科技用5年时间从0做到6亿,如何一枝独秀?
RS|哨兵二号(.SAFE格式)转tif格式
word2003按空格键为什么会出现小数点
leetcode:215无序数组中找第k大的元素
快解析结合友加畅捷U+
蓝牙技术|上半年全国新增 130 万台充电桩,蓝牙充电桩将成为市场主流
MySQL优化学习笔记