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. QQuickView to QQmlApplicationEngine
QtWS25 Last Chance

QQuickView to QQmlApplicationEngine

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 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
    Aleph
    wrote on last edited by
    #1

    Hello everyone :)

    i am making samples for getting used to change Class with the same function like "paraphrasing"

    But there is a problem
    QQmlApplicationEngine is bullying me.

    here is codes

    Original

    qmlRegisterType<QVTKFrameBufferObjectItem>("VtkQuick", 1, 0, "VtkRenderWindow");

    QQuickView view;
    view.setSource(QUrl::fromLocalFile(PROJECT_SOURCE_DIR "//main.qml"));
    QList<QVTKFrameBufferObjectItem*> vtkItems = view.rootObject()->findChildren<QVTKFrameBufferObjectItem*>();

    i want to change QQuickView to QQmlApplicationEngine but i couldn't

    Changed

    qmlRegisterType<QVTKFrameBufferObjectItem>("VtkQuick", 1, 0, "VtkRenderWindow");

    QQmlApplicationEnging engine;
    engine.load(QUrl(QLatin1String("qrc:/main.qml")));
    QList<QVTKFrameBufferObjectItem*> vtkItems = view.rootObjects()->findChildren<QVTKFrameBufferObjectItem*>();

    i thought the function of rootObject() and rootObjects() is the same.
    but it didn't work.

    Could you please tell me what should be different from QQuickView?

    If you make me know differences of QQmlApplicationEngine compared with QQuickView, it's going to be perfect advice for me.

    Thanks !

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Unlike QQuickView, QQmlApplicationEngine does not automatically create a root window. If you are using visual items from Qt Quick, you will need to place them inside of a Window.

      That is the biggest difference. QQuickView creates a window, so you can have any QML component as root item. For QQmlApplicationEngine, your root component has to be Window or ApplicationWindow. I recommend reading the whole description of QQmlApplicationEngine, it contains some other important aspects.

      Regarding the pointer. Here I'm not sure (and can't check now), but it looks like your call findChildren() on a QList, which does not have such method. Try this instead:

      for (QObject *obj : qAsConst(engine.rootObjects())) {
        vtkItems = obj->findChildren<QVTKFrameBufferObjectItem*>();
        if (!vtkItems.isEmpty())
          break;
      }
      

      Or give your VTK component an objectName and then

      (Z(:^

      A 1 Reply Last reply
      1
      • sierdzioS sierdzio

        Unlike QQuickView, QQmlApplicationEngine does not automatically create a root window. If you are using visual items from Qt Quick, you will need to place them inside of a Window.

        That is the biggest difference. QQuickView creates a window, so you can have any QML component as root item. For QQmlApplicationEngine, your root component has to be Window or ApplicationWindow. I recommend reading the whole description of QQmlApplicationEngine, it contains some other important aspects.

        Regarding the pointer. Here I'm not sure (and can't check now), but it looks like your call findChildren() on a QList, which does not have such method. Try this instead:

        for (QObject *obj : qAsConst(engine.rootObjects())) {
          vtkItems = obj->findChildren<QVTKFrameBufferObjectItem*>();
          if (!vtkItems.isEmpty())
            break;
        }
        

        Or give your VTK component an objectName and then

        A Offline
        A Offline
        Aleph
        wrote on last edited by
        #3

        @sierdzio Thanks for your replying.

        i tried your code, and it seemed work. (i deleted qAsConst, so it worked)

        What it means, there was no error.
        but it didn't work like original code, so i need to find some other way.

        Anyway, your code was helpful.
        it makes me think other ways.
        Thanks a lot! XD

        1 Reply Last reply
        1

        • Login

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