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. Using Quick to Interface with C++

Using Quick to Interface with C++

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 1.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.
  • E Offline
    E Offline
    exiled
    wrote on last edited by
    #1

    Is there a way to represent a Quick object, such as a Button, in C++ as a class such that signals will go to that class when invoked on the Quick object ?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on last edited by
      #2

      Sure, you can use the QMetaObject methods to introspect signals from any object constructed in QML and connect them to whichever signals/slots of QObjects constructed by you.

      You can also do it the other way around, if you expose those QObjects to QML and then do: Component.onCompleted: { myQmlObjectId.someSignalName.connect(someCppQObject.slotName) } for example.

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qnoobish
        wrote on last edited by
        #3

        I think if you have a QML like:

        @
        Item{
        id:"myRoot"
        Button{
        id:"button"
        }
        }
        @

        You could find the child whit id:"button" and use it. I would say something like:
        @
        QObject* myButton = viewer.findChild<QObject*>("button");
        @

        And connect it's signals and slots from "myButton" object.

        In short, software is eating the world.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chrisadams
          wrote on last edited by
          #4

          No, not with the identifier attribute. You need to set the objectName property instead.

          eg:
          @
          Item {
          id: anId
          objectName: aName
          }
          @

          you'd see:

          @
          QObject byId = viewer.findChild<QObject>("anId"); // NULL
          QObject byName = viewer.findChild<QObject>("aName"); // not null.
          @

          Cheers,
          Chris.

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            Qnoobish
            wrote on last edited by
            #5

            [quote author="chrisadams" date="1378340124"]No, not with the identifier attribute. You need to set the objectName property instead.

            eg:
            @
            Item {
            id: anId
            objectName: aName
            }
            @

            you'd see:

            @
            QObject byId = viewer.findChild<QObject>("anId"); // NULL
            QObject byName = viewer.findChild<QObject>("aName"); // not null.
            @

            Cheers,
            Chris.[/quote]

            Ohh yes you are right you need to use the ojectName attribute, my bad.

            In short, software is eating the world.

            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