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. Dynamicly add c++class instances tu qml objects (not with listview)
Forum Updated to NodeBB v4.3 + New Features

Dynamicly add c++class instances tu qml objects (not with listview)

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 2.1k Views 1 Watching
  • 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.
  • 8 Offline
    8 Offline
    888rok
    wrote on last edited by
    #1

    Hi guys &girls,
    I'm writing an application that tracks the head movement from webcam and paint na image over the face. The problem is how to create and bind c++class instance to qml.
    Pseudo c++ code:
    @Class FaceItem{
    String imagePath;
    float scale;
    QVector2D position;
    QVector3D rotation;
    }@

    And now how do I create and bind a qml objects like:
    @Image{
    source:imagePath
    x:position.x
    y:positon.y
    scale:scale
    Rotation {axis: Qt.vector3d(0, 0, 1); angle: rotation_.x }
    }@

    I have tried ListView example (http://qt-project.org/doc/qt-5/qtquick-modelviewsdata-cppmodels.html), but position of list element doesnt work for me, because listview does not permit to overlay two list elements(in my case images).
    Thanks for your help!

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      Have you looked at QQmlEngine::qmlRegisterSingletonType() ?

      This would allow you to define a QObject-based class from C++ with properties corresponding to each value to be passed from C++ to QML. Just emit the notify signal when each value is updated.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      0
      • 8 Offline
        8 Offline
        888rok
        wrote on last edited by
        #3

        Thanks for replay.
        Yes, I have looked at this approach, but I dont understand how to connect an instance of a c++ class with generated qml item.
        Hod do I generate qml items? with javascript?
        How do I connect qml to a class instance? Does QQmlContext::setContextProperty work on dynamicly generated qml items?

        1 Reply Last reply
        0
        • jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by
          #4

          Can you clarify the flow of the application? I'm not sure what is meant by generating of qml items and dynamically generated qml.

          Asking a question about code? http://eel.is/iso-c++/testcase/

          1 Reply Last reply
          0
          • 8 Offline
            8 Offline
            888rok
            wrote on last edited by
            #5

            App flow if using ListView example:
            @For each frame:

            1. when new face is detected
              additem(image, position, rotation)
            2. when face is tracked
              setProperty(position,QVector2d)
              setProperty(rotation,QVector3d)@

            Hope this clarifies my problem.

            1 Reply Last reply
            0
            • 8 Offline
              8 Offline
              888rok
              wrote on last edited by
              #6

              Nevermind, I got it working with ListView.
              Thank you for you help.

              1 Reply Last reply
              0
              • jeremy_kJ Offline
                jeremy_kJ Offline
                jeremy_k
                wrote on last edited by
                #7

                Thanks for clarifying.

                Another option is to use Qt.createComponent() and createObject() from javascript. The documentation for createComponent covers usage pretty well. The QML dynamic scene example provides a demonstration.

                As long as it works for you, I would stick with the ListView.

                Asking a question about code? http://eel.is/iso-c++/testcase/

                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