Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Insert QML in a QQuickWidget
Qt 6.11 is out! See what's new in the release blog

Insert QML in a QQuickWidget

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AntoineLet
    wrote on last edited by
    #1

    Hi everyone,
    I am very new to QT5.9. I looked on the forum and QT documentation but I couldnt find a way to solve my problem.

    I am trying to set up a software which controls a Arduino with uart. This part work fine, and is written in C++. I would now like to add a visual feedback of what is happening with a usb webcam. I found this code

    https://github.com/alex-spataru/QCCTV

    which is exactly what I need to add to my software (many thanks to Alex Spataru).

    I was able to merge my code and his, but I am not sure how to put the qml code (from QCCTV project) into a widget. I my mainWindow constructor I added the lines from QCCTV project :

    /*From QCCTV*/
    QGuiApplication::setApplicationName("Awake Monitoring");//("QCCTV Camera");
    QGuiApplication::setOrganizationName("Labeo Technologies"); //("Alex Spataru");
    QGuiApplication::setApplicationVersion("1.0");
    QGuiApplication::setOrganizationDomain("www.labeotech.com"); //(APP_WEBSITE);
    
    /* Set application attributes */
    QGuiApplication::setAttribute (Qt::AA_ShareOpenGLContexts);
    QGuiApplication::setAttribute (Qt::AA_EnableHighDpiScaling);
    
    /* Initialize application */
    QQuickStyle::setStyle ("Material");
    QCCTV_LocalCamera* qcctvCamera = new QCCTV_LocalCamera();
    
    bool mobile = false;    // Not on mobile device
    
    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty ("isMobile", mobile);
    engine.rootContext()->setContextProperty ("AppDspName", "Awake Monitoring");
    engine.rootContext()->setContextProperty ("AppVersion", "1.0");
    engine.rootContext()->setContextProperty ("QCCTVCamera", qcctvCamera);
    
    /* Add QCCTV image provider */
    QCCTV_ImageProvider* provider = new QCCTV_ImageProvider (qcctvCamera);
    engine.addImageProvider ("qcctv", provider);
    
    /* Load QML interface */
    engine.load (QUrl(QStringLiteral ("qrc:/main_default.qml")));
    

    And replaced the last line with

    /*My line*/
    ui->cameraFeed_qw->setSource(QUrl(QStringLiteral("qrc:/main_default.qml"))); 
    

    in which cameraFeed_qw is a quickWidget I added into Designer. This launches two screen, one with my arduino controls and one with the QCCTV project. My QuickWidget is left as a white blank square.

    I also have "QQuickWidget does not support using windows as a root item.

    If you wish to create your root window from QML, consider using QQmlApplicationEngine instead. " warning.

    Can someone help me with this ? Many thanks in advance,

    Antoine

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fheanor
      wrote on last edited by
      #2

      ui->cameraFeed_qw->setSource(QUrl(QStringLiteral("qrc:/main_default.qml"))); should be fine.

      Usually, I write it like that:
      ui->cameraFeed_qw->setSource(QUrl::fromLocalFile(QML_FILE_DEFINITION));

      What is wrong about your code is in QML. As it says QQuickWidget does not support using windows as a root item, you probably wrote something like ApplicationWindow{Item {....}} .
      So if you read carefully, you will understand that QQuickWidget does not support ApplicationWindow as a root.

      So basically, you just need to delete it from your code.
      Now your Qml will be something like that :

      //ApplicationWindow {
      Item {
      ...
      }
      //}
      
      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved