当前位置:网站首页>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讲解
边栏推荐
- CCF GLCC officially opened | Kyushu Cloud open source experts bring generous bonuses to help universities promote open source
- X射线掠入射聚焦反射镜
- SQL语句的写法:Update、Case、 Select 一起的用法
- How to automatically renew the token after it expires?
- Next -21- 添加相册系列 - 1- 框架设置
- 郑轻新生校赛和中工选拔赛题解
- CF1527D MEX Tree (mex & tree & inclusive)
- leetcode: 250. Count subtrees of equal value
- leetcode: 241. Designing precedence for arithmetic expressions
- 微软表示将向内部网络安全专家共享数据 为企业提供更安全保护
猜你喜欢

用于X射线聚焦的复合折射透镜
![[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

uni-app 从零开始-生命周期(二)

leetcode: 212. Word Search II

C# SolidWorks二次开发---工程图简单版标注孔信息

程序猿七夕礼物-如何30分钟给女朋友快速搭建专属语聊房

Bluetooth Technology|In the first half of the year, 1.3 million charging piles were added nationwide, and Bluetooth charging piles will become the mainstream of the market

JCMsuite Application: Oblique Plane Wave Propagation Transmission Through Aperture

leetcode: 253. How many meeting rooms are required at least

期货开户之前要谈好最低手续费和交返
随机推荐
leetcode:259. 较小的三数之和
vim common operation commands
Makefile 语法及使用笔记
【 HMS core 】 【 Media 】 online video editing service 】 【 material can't show, or network anomalies have been Loading state
JCMsuite Application: Oblique Plane Wave Propagation Transmission Through Aperture
没有Project Facets的解决方法
Why does the decimal point appear when I press the space bar in word 2003?
苏秋贵:揭秘绿联科技用5年时间从0做到6亿,如何一枝独秀?
企业级优化
I/O stream summary
AOSP built-in APP franchise rights white list
四平方和,激光炸弹
【剑指offer33】二叉搜索树的后序遍历序列
leetcode: 212. Word Search II
属于程序猿的浪漫
技术分享| 小程序实现音视频通话
OAID是什么
杭电校赛(逆袭指数)
How to write SQL statements: the usage of Update, Case, and Select together
什么,你告诉我?作用域也分种类?