C++与QML信号交互(非Q_PROPERTY法)
发布日期:2021-06-30 10:57:16
浏览次数:2
分类:技术文章
本文共 1613 字,大约阅读时间需要 5 分钟。
运行截图如下:
源码如下:
widget.h
#ifndef WIDGET_H#define WIDGET_H#includenamespace Ui {class Widget;}class Widget : public QWidget{ Q_OBJECTpublic: explicit Widget(QWidget *parent = 0); ~Widget();signals: void sendMsg();public slots: void qmlSlot();private: Ui::Widget *ui;};#endif // WIDGET_H
main.cpp
#include "widget.h"#includeint main(int argc, char *argv[]){ QApplication a(argc, argv); Widget w; w.show(); return a.exec();}
widget.cpp
#include "widget.h"#include "ui_widget.h"#include#include #include #include Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget){ ui->setupUi(this); ui->quickWidget->setSource(QUrl("qrc:/test.qml")); QObject *pRoot = (QObject*)ui->quickWidget->rootObject(); Q_ASSERT(pRoot); connect(pRoot, SIGNAL(qmlSignal()), this, SLOT(qmlSlot())); connect(ui->pushButton, SIGNAL(clicked(bool)), pRoot, SIGNAL(cSignal())); const QMetaObject *metaObject=pRoot->metaObject(); const QMetaObject *thisObject=this->metaObject();}Widget::~Widget(){ delete ui;}void Widget::qmlSlot(){ ui->pushButton->setText("qmlSlot called!");}
test.qml
import QtQuick 2.0Rectangle { id: root color: "green" Text { id: myText text: qsTr("hello") font.pixelSize: 70 color: "red" anchors.centerIn: parent } signal qmlSignal signal cSignal MouseArea { anchors.fill: parent onClicked: qmlSignal() } onCSignal: { root.color = "yellow" myText.text = "how are you?" }}
转载地址:https://it1995.blog.csdn.net/article/details/83155147 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月25日 15时44分17秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
在centos7上部署 redis 和基本操作
2019-04-30
redis配置文件的持久化(详细对比)
2019-04-30
squid代理-----透明代理模式
2019-04-30
squid代理介绍----ACL控制应用+sarg日志分析+反向代理
2019-04-30
redis集群之主从模式+哨兵模式
2019-04-30
rsync远程同步(rsync源服务器+inotify实时同步)
2019-04-30
GlusterFS原理及如何配置使用
2019-04-30
shell之条件测试和if语句
2019-04-30
shell脚本之case-for-while-until语句
2019-04-30
shell脚本小案例之九九乘法表、幸运大抽奖、简易计算器
2019-04-30
shell脚本之函数和数组(含案例,适合新手练习)
2019-04-30
shell脚本之数组的升降序排序,插入排序
2019-04-30
shell脚本之正则表达式(grep 和 egrep命令详解)
2019-04-30
shell脚本之sed工具使用
2019-04-30
shell脚本之awk工具详解
2019-04-30
shell脚本之排序工具(sort、uniq)
2019-04-30
shell脚本之expect免交互
2019-04-30
shell编程之实战----MAC记录与端口扫描脚本、开发系统监控脚本
2019-04-30
ELK日志分析系统原理与部署
2019-04-30
Nginx访问状态以及基于多域名、多端口、多IP配置虚拟主机
2019-04-30