qml

setContextProperty qmlRegisterType qRegisterMetaType等区别

杀马特。学长 韩版系。学妹 提交于 2020-02-16 00:04:29
1,setContextProperty 如果要使用单个全局类来访问QML或从QML访问.这里您需要在使用setContextProperty()之前创建此类对象。就是说 类实列化一次,QML中可以直接使用这个类。 如: MainController mainController; engine.rootContext()->setContextProperty("MainController", &mainController); 则QML中可直接使用 MainController。 2,qmlRegisterType 将C++实现的类在QML中调用的。与1 不一样,全局不唯一。 如: qmlRegisterType<AgoraWeb>("AgoraWeb",1,0,"AgoraWeb"); 每个QML中 会自己实例化一份内存。 Item { id:root property bool isMaster: false AgoraWeb{ id:agoraWeb } 3,qRegisterMetaType Qt信号槽中使用自定义类型,需要注意使用qRegisterMetaType对自定义类型进行注册 步骤:(以自定义TextNumber类型为例) 自定一种类型,在这个类型的顶部包含:#include <QMetaType> 在类型定义完成后,加入声明:Q_DECLARE

Qt 程序发布指南

只谈情不闲聊 提交于 2020-02-12 11:47:09
Qt 程序发布指南 威武的涛哥 的博客文章地址 https://jaredtao.github.io/2019/09/02/Qt%E5%AE%9E%E7%94%A8%E6%8A%80%E8%83%BD6-%E7%A8%8B%E5%BA%8F%E5%8F%91%E5%B8%83%E6%8C%87%E5%8D%97/ 知乎文章地址 https://zhuanlan.zhihu.com/p/80919147 简介 背景 Qt的安装 Qt的目录结构 Qt安装路径 Qt核心路径 HelloDeploy Window编译和发布 Window 编译 Window 发布 VS运行时库 常见的错误处理 应用程序无法正常启动 启动失败 - no Qt platform plugin OpenGL Context 创建失败 整理 简单裁剪 删减dll 删减plugins 删减qml 简介 本文是《Qt实用技能》系列文章的第六篇,涛哥在这里讨论发布Qt应用程序的知识点。 (第五篇《Qt实用技能5-掌握信号槽使用细节》还在整理中,过几天会发) 背景 有很多人向涛哥询问,Qt程序发布的相关问题,网络上虽然可以搜到一大堆教程,但是可靠的比较少。 所以这次尽我所能,全面、详细地整理一些Qt程序发布的知识点,希望能帮助到更多人。 对老手来说,很多坑都踩过了,无非就是把正确的dll放在正确的路径。 对新手来说

20200207-02 QML 动态添加子类(TableView 动态添加 Column)

自闭症网瘾萝莉.ら 提交于 2020-02-08 00:28:23
前言: 本文讲解方法,不适用动态删除添加对象的,这种方法查看链接 动态删减通过JavaScript 应用场景如:TableView 动态添加 Column 正文: The data property allows you to freely mix visual children and resources in an item. If you assign a visual item to the data list it becomes a child and if you assign any other object type, it is added as a resource. 翻译:QML 中的 data 属性本质上是 list<QObject> 数据对象列表,所有可视化部分属于 children 部分,非可视化属于 resources 部分 //推荐标准写法: Item { Text {} Rectangle {} Timer {} } //上面写法代替下面这种写法: instead of : Item { children: [ Text{} Rectangle {} ] resources: [ Timer {} ] } It should not generally be necessary to refer to the data property, as

Qt : How to monitor a Q_PROPERTY change on C++ side instead of QML

独自空忆成欢 提交于 2020-02-06 11:28:51
问题 I am using Qt 5.9.3. I have following property declared in my app's main.qml Code: //main.qml MyQuickItem { property color nextColor onNextColorChanged: { console.log("The next color will be: " + nextColor.toString()) } } // MyQuickItem.h class MyQuickItem : public QQuickItem { } Question: How can I make onNextColorChanged be defined in the C++ side? I know that I can also make nextColor as a property inside C++ class MyQuickItem . like so // MyQuickItem.h class MyQuickItem : public

Qt : How to monitor a Q_PROPERTY change on C++ side instead of QML

随声附和 提交于 2020-02-06 11:27:19
问题 I am using Qt 5.9.3. I have following property declared in my app's main.qml Code: //main.qml MyQuickItem { property color nextColor onNextColorChanged: { console.log("The next color will be: " + nextColor.toString()) } } // MyQuickItem.h class MyQuickItem : public QQuickItem { } Question: How can I make onNextColorChanged be defined in the C++ side? I know that I can also make nextColor as a property inside C++ class MyQuickItem . like so // MyQuickItem.h class MyQuickItem : public

Camera Not saving the captured image

£可爱£侵袭症+ 提交于 2020-02-06 08:22:47
问题 I Use Qt 5.12.5 and I have qt quick controls 2 project that I run it on my Android Device. Now I have a problem,the signal imageSaved of Camera Not trigger? In below when I click button Camera should capture Button{ onClicked: { camera.imageCapture.capture(); } } After Clicking the Button imageCaptured signal runs, the photoPrevew shows the captured image ,But onImageSaved Not running and I don't see any captured image in my Gallery! Camera { id: camera position: Camera.BackFace

Does Qt Qml Have QMdiArea?

坚强是说给别人听的谎言 提交于 2020-02-05 04:04:36
问题 Does Qml have QMdiArea and QMdiSubWindow? If so can you show me a little example? I have a cool idea for a program design that I would like to create. 回答1: QML does not have something like QMdiArea. But you can place your qml file in a QMdiArea widget. It's enought to set a QDeclarativeView as viewport widget of the QMdiArea or by putting the QDeclarativeView inside QMdiArea(It's just a QWidget subclass like any other). 来源: https://stackoverflow.com/questions/22682057/does-qt-qml-have

Does Qt Qml Have QMdiArea?

二次信任 提交于 2020-02-05 04:04:28
问题 Does Qml have QMdiArea and QMdiSubWindow? If so can you show me a little example? I have a cool idea for a program design that I would like to create. 回答1: QML does not have something like QMdiArea. But you can place your qml file in a QMdiArea widget. It's enought to set a QDeclarativeView as viewport widget of the QMdiArea or by putting the QDeclarativeView inside QMdiArea(It's just a QWidget subclass like any other). 来源: https://stackoverflow.com/questions/22682057/does-qt-qml-have

QML conditional Binding not working as expected

空扰寡人 提交于 2020-02-03 04:31:40
问题 If I have a simple Binding object of the form: Rectangle { height: 400 width: 500 property var someObj: null Binding on color { when: someObj value: someObj.color } } Then I would expect that when someObj is not null , someObj 's color property is bound to this object's color property. What I actually get is a runtime error message: TypeError: Cannot read property 'color' of null Any reason why this doesn't work? Doing the almost equivalent JavaScript expression: color: { if ( someObj != null

QML conditional Binding not working as expected

拈花ヽ惹草 提交于 2020-02-03 04:31:25
问题 If I have a simple Binding object of the form: Rectangle { height: 400 width: 500 property var someObj: null Binding on color { when: someObj value: someObj.color } } Then I would expect that when someObj is not null , someObj 's color property is bound to this object's color property. What I actually get is a runtime error message: TypeError: Cannot read property 'color' of null Any reason why this doesn't work? Doing the almost equivalent JavaScript expression: color: { if ( someObj != null