Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How does List allocate space using a custom structure in QML?



  • property var keyValueList[KeyValue{},KeyValue{}] //Error Code

    class KeyValue : public QObject
    {
      Q_OBJECT
      Q_PROPERTY(QString key READ getKey WRITE setKey NOTIFY keyChanged)
      Q_PROPERTY(QString value READ getValue WRITE setValue NOTIFY valueChanged)
    
     public:
      KeyValue(const QString& key, const QString& value, QObject* parent = 0);  
    
     signals:
      void keyChanged();
      void valueChanged();
    
     private:
      QString _key;
      QString _value;
    
      QString getKey() const;
      QString getValue() const;
    
      void setKey(const QString& key);  
      void setValue(const QString& value);
    };
    Q_DECLARE_METATYPE(KeyValue*)
    
    qmlRegisterType<KeyValue>("customqml", 1, 0, "KeyValue");
    
    import QtQuick 2.7
    import customqml 1.0
    
    Item{
      KeyValue {
        id: idKeyValue 
      }
      property var keyValueList[KeyValue{},KeyValue{}] //***Error Code***
    }
    


  • @sierdzio

    I just tested that the specified type needs to be stored in list
    Like this,
    property list<KeyValue> rects: [
    KeyValue{},
    KeyValue{}
    ]


  • Moderators

    Is there any question you want to ask?

    property var keyValueList[KeyValue{},KeyValue{}] //***Error Code***
    

    This is simply invalid syntax in QML. But I don't know what you want to achieve - without more info I can't help more.



  • @sierdzio

    I just tested that the specified type needs to be stored in list
    Like this,
    property list<KeyValue> rects: [
    KeyValue{},
    KeyValue{}
    ]


Log in to reply