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. Manipulating unknown types from c++.
Forum Update on Monday, May 27th 2025

Manipulating unknown types from c++.

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 3.1k Views
  • 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.
  • L Offline
    L Offline
    llamatron
    wrote on 21 Oct 2010, 10:27 last edited by
    #1

    Hi,

    I'm trying to do some manipulation (serialisation/deserialisation etc) of qml types in c++, and am having some difficulty with properties of unknown types (i.e. for which there are only qml components).

    Let's say I have the following qml objects.

    TypeA.qml
    @import Qt 4.7
    QtObject {
    property string name
    property int number
    }
    @
    TypeB.qml
    @import Qt 4.7
    QtObject {
    property TypeA singleTypeA
    property list<TypeA> lotsOfAs
    }
    @

    In native code I want to be able to do normal stuff like create, add, remove & modify the properties in TypeB. I can at the moment set and get properties fine on objects like TypeA, because it's properties are QVariants of known types.

    Do qml types inherently shallow copy? or is there some way using Object::setProperty and Object::property to access instances of unknown qml types directly (i.e. to their base QObject* or anything else that can be cast using qobject_cast)? The objects are in fairly complex hierarchies and I'd prefer to be working on pointers directly to those objects.

    In the case of the list, if I look at the metaproperty, it is of type QVariant::UserType, and the typename is e.g. QDeclarativeListProperty<TypeA_QMLTYPE_2>. My understanding is that QDeclarativeListProperty is a wraper for an underlying list instance (say of type QObject*), but I don't know how to get from the QVariant to something like QList<QObject*>*.

    Cheers,
    Simon

    1 Reply Last reply
    0
    • L Offline
      L Offline
      llamatron
      wrote on 22 Oct 2010, 00:57 last edited by
      #2

      Found the answers...

      For QObjects they can just be cast using qvariant_cast<QObject*>(variant).
      For qml created lists use a QDeclarativeListReference, making sure to pass in the engine.

      1 Reply Last reply
      0

      1/2

      21 Oct 2010, 10:27

      • Login

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