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. QList of C++ custom objects to QML

QList of C++ custom objects to QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 2.7k 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.
  • bguivarchB Offline
    bguivarchB Offline
    bguivarch
    wrote on last edited by
    #1

    Hello,

    Here is my need. I am reading an XML file in the C++ side of my application, and create some C++ objects of mine. After the reading, I send a signal to the QML to tell my GUI it has some QML components to dynamically instanciates.
    I want those components to be initialized with the properties of the C++ objects I have created during the reading of the XML file.
    So the idea here is to send a list of C++ objects to the QML, and parse that list inside the QML to create components.
    I had a look at the QVariant class, but don't really know how to use it.
    For example, I currently have a QList<MyObjects*> that I want to expose to the QML via a Q_INVOKABLE method.
    How do I do that? Does a QList<QVariant*> will be enought?

    Regards,

    raven-worxR 1 Reply Last reply
    0
    • bguivarchB bguivarch

      Hello,

      Here is my need. I am reading an XML file in the C++ side of my application, and create some C++ objects of mine. After the reading, I send a signal to the QML to tell my GUI it has some QML components to dynamically instanciates.
      I want those components to be initialized with the properties of the C++ objects I have created during the reading of the XML file.
      So the idea here is to send a list of C++ objects to the QML, and parse that list inside the QML to create components.
      I had a look at the QVariant class, but don't really know how to use it.
      For example, I currently have a QList<MyObjects*> that I want to expose to the QML via a Q_INVOKABLE method.
      How do I do that? Does a QList<QVariant*> will be enought?

      Regards,

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @bguivarch said in QList of C++ custom objects to QML:

      How do I do that? Does a QList<QVariant*> will be enought?

      Yes. But use QList<QVariant> instead. When you registered the list contents (in the variant) to the meta type system (Q_DECLARE_METATYPE) you can access it's QObject properties from QML.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • bguivarchB Offline
        bguivarchB Offline
        bguivarch
        wrote on last edited by
        #3

        Hello,

        Thanks for your answer.

        To access the properties of the objects in the list, do I have to convert these properties to Q_PROPERTY or is that unnecessary? With my understanding of QML, I would say that I have to.

        Regards

        raven-worxR 1 Reply Last reply
        0
        • bguivarchB bguivarch

          Hello,

          Thanks for your answer.

          To access the properties of the objects in the list, do I have to convert these properties to Q_PROPERTY or is that unnecessary? With my understanding of QML, I would say that I have to.

          Regards

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @bguivarch said in QList of C++ custom objects to QML:

          With my understanding of QML, I would say that I have to.

          exactly, since QML uses the meta type system.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • bguivarchB Offline
            bguivarchB Offline
            bguivarch
            wrote on last edited by
            #5

            Hello,

            Ok thanks for this additional explanation.
            I'll give it a try and let you know if I face some difficulties.

            Regards

            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