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. QML Loader Object
Forum Updated to NodeBB v4.3 + New Features

QML Loader Object

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 3.5k 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.
  • C Offline
    C Offline
    cokefish
    wrote on 17 Jul 2012, 12:08 last edited by
    #1

    We always us QML to make application having a beautiful GUI, and can be controlled by mouse on the elements on it.

    But this time I have got a problem.
    I make a application with two windows, one is a QML window, and the other is a common dialog window.
    The QML window is not controlled directly by mouse, but rather by the dialog window.

    The QML window have many pages, When I want the page content to be changed, I use a "Loader" in QML item to load some other qml file to screen.

    Then it is the problem.
    If I want to control the elements on some other qml, for example Text, or Image object.
    I cannot access them in cpp file.

    Would you please give me some method on my problem?
    I cost one day on this, but I did not have any solution.
    Thank you.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 17 Jul 2012, 17:37 last edited by
      #2

      In QML, subobjects of the file loaded by Loader are accessible through the "item" property. Does it not work with C++, or you have not tried?

      (Z(:^

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cokefish
        wrote on 18 Jul 2012, 00:07 last edited by
        #3

        But I need to use it in cpp file.

        “item” property
        In cpp file, how I can use it?
        I think it is just a property.
        If I can change it into a object pointer by type cast?
        like below
        #-----------------------------
        QGraphicsObject *subobject =
        qobject_cast<QGraphicsObject *>(v->rootObject()->findChild<QObject *>("mainloader")->property("item"));
        #-----------------------------

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cokefish
          wrote on 18 Jul 2012, 02:59 last edited by
          #4

          And what is more,
          the sentences
          #--------------------------
          (v->rootObject()->findChild<QObject >(“mainloader”)->property(“item”))
          #--------------------------
          returns a QVariant(QGraphicsObject
          , ) value.
          But I cannot convert it to a QGraphicsObject* pointer.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dmcr
            wrote on 18 Jul 2012, 09:55 last edited by
            #5

            a property in accessible in QML coul be of multiple kind int, string, .... see "here":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativebasictypes.html.

            But in C++you had to create some code like"int this documentation.":http://doc.qt.nokia.com/4.7-snapshot/qml-extending.html#object-and-list-property-types

            dmcr

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sierdzio
              Moderators
              wrote on 18 Jul 2012, 10:06 last edited by
              #6

              Please wrap your code in '@' tags.

              Try this:
              @
              (v->rootObject()->findChild<QObject *>(“mainloader”)->property(“item”)).value<QGraphicsObject>();
              @

              (Z(:^

              1 Reply Last reply
              0
              • C Offline
                C Offline
                cokefish
                wrote on 18 Jul 2012, 12:19 last edited by
                #7

                @ (v->rootObject()->findChild<QObject *>(“mainloader”)->property(“item”)).value<QGraphicsObject>();@

                This may not work.
                I tried similar method today.

                I will confirm it again tomorrow.

                1 Reply Last reply
                0

                6/7

                18 Jul 2012, 10:06

                • Login

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