当前位置:网站首页>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: 编译运行
边栏推荐
- What should I do if the neural network cannot be trained?
- Selenium:简介
- The sword refers to Offer 68 - I. Nearest Common Ancestor of Binary Search Trees
- 剑指 Offer 68 - II. 二叉树的最近公共祖先
- 请问shake数据库中为什么读取100个collection 后,直接就退出了,不继续读了呢?
- typescript26 - literal types
- pytroch、tensorflow对比学习—专栏介绍
- (2022牛客多校四)K-NIO‘s Sword(思维)
- Selenium:表单切换
- Robot_Framework:常用内置关键字
猜你喜欢
Robot_Framework: Assertion
A,H,K,N
API Design Notes: The pimpl trick
备战金九银十,如何顺利通过互联网大厂Android的笔面试?
Dry goods!How to Construct SRv6-TE Performance Test Environment Using Instrumentation
Robot_Framework: commonly used built-in keywords
(Codeforce 757)E. Bash Plays with Functions(积性函数)
Malicious attacks on mobile applications surge by 500%
牛客多校2022第四场A,H,K,N
华为Android开发面试后得出的面试秘诀
随机推荐
The method of solving stored procedure table name passing through variable in mysql
用控件当画笔获得bitmap代码记录
API设计笔记:pimpl技巧
文件的异步读写
Check控件
MySQL-数据操作-分组查询-连接查询-子查询-分页查询-联合查询
LeetCode 9. 回文数
Li Chi's work and life summary in July 2022
LeetCode 231. 2 的幂
LeetCode 27. 移除元素
HJS-DE1/2时间继电器
Logitech Mouse Experience Record
About making a progress bar for software initialization for Qt
Selenium: form switching
pytroch、tensorflow对比学习—专栏介绍
程序员代码面试指南 CD15 生成窗口最大值数组
Seleniu:元素常用操作
(2022牛客多校四)H-Wall Builder II(思维)
PaddleX部署推理模型和GUI界面测试结果不一致的解决方法
【MySQL必知必会】 表的优化 | 充分利用系统资源