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. QVector or std::vector to qml

QVector or std::vector to qml

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 8.6k 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.
  • J Offline
    J Offline
    Jjcasmar
    wrote on last edited by
    #1

    Hi,

    I'm developing an app where I must pass some data stored in vector (QVector or std::vector, I dont care) to qml.

    I have been looking in Google how to do this but there's is a lot of non clear information and I'm new to QML so its hard for me to understand it.

    My class has a property of this type:
    Q_PROPERTY(QVector<float> distance READ distance NOTIFY distanceChanged)

    So my question is, how can I pass a property like that to QML?
    I'm using Qt 5.7

    Thanks!

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! For an in-depth explanation see Exposing Attributes of C++ Types to QML. QVector<float> to QML is not supported transparently, instead QVariantList is used. More info can be found in Sequence Type to JavaScript Array.

      VRoninV 1 Reply Last reply
      2
      • J Offline
        J Offline
        Jjcasmar
        wrote on last edited by
        #3

        Thanks Wieland!

        I'm studying the QML documentation :-)

        1 Reply Last reply
        0
        • ? A Former User

          Hi! For an in-depth explanation see Exposing Attributes of C++ Types to QML. QVector<float> to QML is not supported transparently, instead QVariantList is used. More info can be found in Sequence Type to JavaScript Array.

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @Wieland said in QVector or std::vector to qml:

          QVector<float> to QML is not supported transparently

          in Sequence Type to JavaScript Array:

          In particular, QML currently supports: [...] QVector<qreal>

          So it might be natively supported (if you configured qt to use float, which is unusual) or is pretty close to be natively supported if you are open to switch to double precision floating points instead

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          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