当前位置:网站首页>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: 编译运行

边栏推荐
- 2022年超全的Android面经(附含面试题|进阶资料)
- 【目标检测】YOLOv7理论简介+实践测试
- Error: AttributeError: module 'matplotlib' has no attribute 'figure'
- 万字逐行解析与实现Transformer,并进行德译英实战(二)
- PAT serie b write the number 1002
- (2022牛客多校四)N-Particle Arts(思维)
- Use controls as brushes to get bitmap code records
- LeetCode 387. 字符串中的第一个唯一字符
- [target detection] YOLOv7 theoretical introduction + practical test
- 程序员代码面试指南 CD15 生成窗口最大值数组
猜你喜欢

可持久化线段树

II. Binary tree to Offer 68 - recent common ancestor

牛客多校2022第四场A,H,K,N

WPF项目-初步了解数据绑定 binding

pytroch、tensorflow对比学习—功能组件(数据管道、回调函数、特征列处理)

(2022牛客多校四)A-Task Computing (排序+动态规划)

UE4 rays flashed from mouse position detection

USB3.0:VL817Q7-C0的LAYOUT指南(三)

pytorch、tensorflow对比学习—计算图和微分机制

The solution to the inconsistency between the PaddleX deployment inference model and the GUI interface test results
随机推荐
25. 这三道常见的面试题,你有被问过吗?
DL-31/6电流继电器
vim configuration + ctag is as easy to read code as source insight
程序员代码面试指南 CD15 生成窗口最大值数组
state compressed dp
冲刺金九银十,Android开发面试(内含面试资料|面试题|源码)
API设计笔记:pimpl技巧
万字逐行解析与实现Transformer,并进行德译英实战(三)
Immutable
ApiFile
Immutable
状态压缩dp
A,H,K,N
MySQL-Data Definition Language-DDLdatebase define language
PAT class B 1001 (3n+1) conjecture
Selenium:操作Cookie
USB3.0:VL817Q7-C0的LAYOUT指南(二)
Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)
剑指 Offer 68 - II. 二叉树的最近公共祖先
ModuleNotFoundError: No module named ‘tensorflow.keras‘报错信息的解决方法