当前位置:网站首页>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: 编译运行
边栏推荐
- Malicious attacks on mobile applications surge by 500%
- Challenge 52 days to memorize Peppa Pig (Day 01)
- (2022牛客多校四)N-Particle Arts(思维)
- 微信小程序用户登录auth.code2Session接口开发
- 25. Have you been asked these three common interview questions?
- 关于给Qt做一个软件初始化的进度条
- The sword refers to Offer 68 - I. Nearest Common Ancestor of Binary Search Trees
- Robot_Framework:断言
- pytorch、tensorflow对比学习—功能组件(优化器、评估指标、Module管理)
- state compressed dp
猜你喜欢
剑指 Offer 68 - I. 二叉搜索树的最近公共祖先
Robot_Framework: keyword
High Numbers | 【Re-integration】Line Area Score 880 Examples
Check控件
II. Binary tree to Offer 68 - recent common ancestor
Pyspark Machine Learning: Vectors and Common Operations
(2022 Niu Ke Duo School IV) N-Particle Arts (Thinking)
y83. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Advanced Prometheus Alarm Mechanism (14)
(2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)
(2022 Nioke Duo School IV) D-Jobs (Easy Version) (3D prefix or)
随机推荐
图片更新之后Glide加载依旧是原来的图片问题
Selenium:简介
pytorch、tensorflow对比学习—功能组件(激活函数、模型层、损失函数)
【MySQL必知必会】 表的优化 | 充分利用系统资源
typescript25 - type assertion
混合型界面:对话式UI的未来
MySQL-Data Definition Language-DDLdatebase define language
The sword refers to Offer 68 - I. Nearest Common Ancestor of Binary Search Trees
y83.第四章 Prometheus大厂监控体系及实战 -- prometheus告警机制进阶(十四)
(2022 Niu Ke Duo School IV) K-NIO's Sword (Thinking)
将CSV文件快速导入MySQL中
The solution to the inconsistency between the PaddleX deployment inference model and the GUI interface test results
[MySQL] 多表查询
LeetCode 231. 2 的幂
HJS-DE1/2时间继电器
typescript23-tuple
(2022牛客多校四)D-Jobs (Easy Version)(三维前缀或)
Pyspark Machine Learning: Vectors and Common Operations
I met a shell script
SL-12/2过流继电器