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. Must Q_PROPERTYs with user-defined C++ types be of pointer type?
Forum Updated to NodeBB v4.3 + New Features

Must Q_PROPERTYs with user-defined C++ types be of pointer type?

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 410 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
    Edwin Vane
    wrote on last edited by
    #1

    Consider the following simple example:

    namespace MyNamespace {
    class MyPoint {
        Q_OBJECT
        Q_PROPERTY(float x READ CONSTANT);
        ...
    };
    class Circle {
        Q_OBJECT
        Q_PROPERTY(MyNamespace::MyPoint centre READ centre NOTIFY centreChanged);
        ...
    };
    }
    Q_DECLARE_METATYPE(MyPoint);
    
    

    An instance of Circle is set as a context property for some qml so it can be used:

    Rectangle {
        x: circleProperty.centre.x
        y: circleProperty.centre.y
        ...
    }
    

    MyPoint is registered using qmlRegisterType<MyPoint>(...). However, this function only calls qRegisterMetaType for MyPoint* and QDeclarativeListProperty<MyPoint> so when I run my app, I get qml errors saying it doesn't know about the MyNamespace::MyPoint type.

    The errors go away if I explicitly use qRegisterMetaType<MyPoint>("MyNamespace::MyPoint"); although now QtQuick won't read through the circleProperty.centre property access to get x. If I print circleProperty.centre it says QVariant(MyNamespace::MyPoint) which is fine but circleProperty.centre.x is undefined.

    Given the behaviour of qmlRegisterType and the errors I see if I work around the behavior, it seems like what I'm trying to do with properties of C++ types without using pointers is not supported. Is that so?

    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