how to integrate qml file into qt-widgets app?

心不动则不痛 提交于 2019-12-04 20:34:03
techneaz

1. QDeclarativeView is for older Qt versions. If you are porting an application to Qt 5 then you can refer this documentation.

2. For your application you can use the new class in Qt 5.x QuickView as shown below.

Create a layout in your ui. Or do it via code. Then add the view to the layout as shown below:

QQuickView *view = new QQuickView();
QWidget *container = QWidget::createWindowContainer(view, this);
container->setMinimumSize(300, 200);
container->setMaximumSize(300, 200);

view->setSource(QUrl("qrc:/test.qml")); // Fetch this url by right clicking on your resource file.
ui->verticalLayout->addWidget(container);

3. In the .pro file just add quick module:

+quick

4. Reference: Introducing QWidget::createWindowContainer()

5. Note: If you have to add a url to a resource file you have to use :/ refer here for more details.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!