当前位置:网站首页>Qt Widget 项目对qml的加载实例
Qt Widget 项目对qml的加载实例
2022-08-01 05:13:00 【王恺瑞】
step1:首先我们新建一个widget工程,File --》新建项目 --》 Application --》 Qt Widget Application --》...
step2:新建一个qml文件,右键项目名字,选择“添加新文件” --》 Qt --》 QML file --》 .....
此处记录了关键步骤,后续常规步骤没有罗列。新建完成后目录结构如下:
step 3:编辑qml文件,添加代码,添加一个显示界面
源码:
import QtQuick 2.0
import QtQuick.Controls 2.1
import QtQuick.Window 2.0
Window { /*新建一个显示界面*/
visible: true /*设置显示界面可见*/
height: 480
width: 640 /*设置界面高宽*/
title: "QML load test" /*设置界面标题*/
}
step 4: main.cpp 中添加相关代码,并屏蔽widget 显示界面
源码:
#include "widget.h"
#include <QApplication>
#include <QQmlApplicationEngine> /*添加头文件*/
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
/*屏蔽 widget 显示界面*/
//Widget w;
//w.show();
QQmlApplicationEngine qmleng; /*实例化 qmleng 对象*/
qmleng.load(QUrl(QStringLiteral("../appLoadQml/uiQml.qml"))); /*通过 qmlengine 显示界面*/
return a.exec();
}
step5: 在*.pro 文件中添加 qml 模块
step 6: 编译运行
边栏推荐
- 用控件当画笔获得bitmap代码记录
- 万字逐行解析与实现Transformer,并进行德译英实战(二)
- typescript28 - value of enumeration type and data enumeration
- PAT serie b write the number 1002
- PAT乙级 1001 害死人不偿命的(3n+1)猜想
- typescript27 - what about enumeration types
- 力扣(LeetCode)212. 单词搜索 II(2022.07.31)
- Typescript22 - interface inheritance
- (Codeforce 757) E. Bash Plays with Functions
- Selenium: form switching
猜你喜欢
pytroch、tensorflow对比学习—使用GPU训练模型
The sword refers to Offer 68 - I. Nearest Common Ancestor of Binary Search Trees
零序电流继电器器JL-8C-12-2-2
2022/07/29 入职健海JustFE团队,我学到了高效开发(年中总结)
混合型界面:对话式UI的未来
可视化全链路日志追踪
The difference between scheduleWithFixedDelay and scheduleAtFixedRate
剑指 Offer 68 - II. 二叉树的最近公共祖先
力扣(LeetCode)212. 单词搜索 II(2022.07.31)
(2022牛客多校四)K-NIO‘s Sword(思维)
随机推荐
About making a progress bar for software initialization for Qt
Excel record of integer programming optimization model to solve the problem
ModuleNotFoundError: No module named ‘tensorflow.keras‘报错信息的解决方法
(Codeforce 757) E. Bash Plays with Functions
【目标检测】YOLOv7理论简介+实践测试
Selenium:操作JS
LeetCode 1189. “气球” 的最大数量
Seleniu: Common operations on elements
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
Selenium: mouse, keyboard events
II. Binary tree to Offer 68 - recent common ancestor
USB3.0:VL817Q7-C0的LAYOUT指南(二)
移动应用恶意攻击激增500% 三六零天御为APP免费构建安全屏障
Selenium:元素判断
vim配置+ctag像source insight一样方便阅读代码
Robot_Framework:常用内置关键字
挑战52天背完小猪佩奇(第01天)
(2022 Nioke Duo School IV) H-Wall Builder II (Thinking)
(2022 Niu Ke Duo School IV) N-Particle Arts (Thinking)
25. Have you been asked these three common interview questions?