How to add qml to mainwindow ui file



  • Can somebody help me how to add qml to mainwindow ui. I added a QQuickwidget in mainwindow.ui from designer.

    Then I added following code:

        QQuickView *qmlView = new QQuickView();
        qmlView->setSource(QUrl::fromLocalFile("test.qml"));
        ui->widget->createWindowContainer(qmlView, this);
    
    

    But I can see nothing when I run the program inside QQuickWidget.



  • Hello,
    Pls refer this thread for brief idea about QML integration to widgets.



  • @TobbY . Thanks, I tried this code, but it does not show anything on QML too.


  • Moderators

    @milan said in How to add qml to mainwindow ui file:

    Can somebody help me how to add qml to mainwindow ui. I added a QQuickwidget in mainwindow.ui from designer.

    Then I added following code:

        QQuickView *qmlView = new QQuickView();
        qmlView->setSource(QUrl::fromLocalFile("test.qml"));
        ui->widget->createWindowContainer(qmlView, this);
    
    

    If you added a QQuickWidget via designer, why adding anoher QQuickView via code!?

    just access your QuickWidget and set the source:

    ui->quickWidget->setSource(QUrl(QStringLiteral("qrc:/test.qml")));
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.