QTC++ widget中使用QML编写的UI界面

本文档介绍了如何在QT5的C++ Widget应用中使用QML进行UI设计。通过调用`QWidget::createWindowContainer()`方法,可以将QWindow类型的QQuickView嵌入到QWidget中。虽然这种方法简化了UI集成,但过多使用可能会影响应用性能。文中提供了具体的代码示例,展示了如何创建QQuickView并将其设置为窗口容器,从而将QML界面与C++逻辑结合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

         最近使用QT5写了一个UI,控制逻辑采用C++编写,与QML混合编程。主要实现主机和PLC的交互,编写,实现过程都挺顺利的。之前用C++,Qwidget开发过一个类似于桌面的小程序,有没有办法整合进去,通过该程序启动与PLC的通信。于是翻翻Qwidget帮助文档吧,运气还挺好,找到一个

QWidget * QWidget::​createWindowContainer(QWindow * window, QWidget * parent = 0, Qt::WindowFlags flags = 0)
Creates a QWidget that makes it possible to embed window into a QWidget-based application.

The window container is created as a child of parent and with window flags flags.

Once the window has been embedded into the container, the container will control the window's geometry and visibility. Explicit calls to QWindow::setGeometry(), QWindow::show() or QWindow::hide() on an embedded window is not recommended.

The container takes over ownership of window. The window can be removed from the window container with a call to QWindow::setPar

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值