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. Unable to write properties of Q_GADGET
Forum Updated to NodeBB v4.3 + New Features

Unable to write properties of Q_GADGET

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 186 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.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by beecksche
    #1

    Hi,
    i've defined a QObject derived class and a Q_GADGET struct in C++ to use in QML:

    struct TypeName {
       Q_GADGET
       Q_PROPERTY(QString name MEMBER name)
       QString name;
    }
    
    Q_DECLARE_METATYPE(TypeName)
    
    class MyClass : public QObject {
       Q_OBJECT
       Q_PROPERTY(TypeName type READ type)
    public:
       MyClass() { qRegisterMetaType<TypeName>(); }
       Q_INVOKALBLE Type typeInvoked() const { return m_type; }
       TypeName type() const { return m_type; }
    private:
       TypeName m_type;
    }
    

    If I call the property MyClass.type I'm not able to write the properties of TypeName. But if it is called by the invokable function I can:

    MyClass {
       id: myClass
    }
    
    var typeProperty= myClass.type
    typeProperty.name = "MyName"
    
    var typeInvoked = myClass.typeInvoked()
    typeInvoked.name = "MyName"
    
    console.log(typeProperty.name) // '' <- ?
    console.log(typeInvoked.name) // 'MyName'
    
    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