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

How to use Q_PROPERTY with an array?



  • Hi, I'm having a trouble in use of Q_PROPERTY. Firstly my aim is defining property in QML side. I want to use it as following form:

    class Parameters : public QObject
    {
              Q_OBJECT
        public:
              Parameters(){}
              float Param1[13];
              int Param2[5];
              int Param3
              /*  various 
                 parameters  */
              Q_PROPERTY(float Param3_ MEMBER Param3)          //there is no problem. I can also access in the qml side.
              Q_PROPERTY(float Param1_ MEMBER Para1)             // How can I use this with array. This the line I had trouble.
    

    Instead of defining these parameters as member, I tried to define them in a struct as struct will be the member of this class.
    But I couldn't use the struct with Q_PROPERTY to access this members in qml side.

    How can I handle with this problem. I'm open to these two ways.

    Thanks in advance!


  • Moderators

    float Param1[13];
    MEMBER Para1
    

    Names do not match :-)

    I don't think arrays are supported by QML engine. Use QList, QVariantList or a similar construct instead.



  • It works when I use QVector. It didn't come my mind :) Thanks a lot :)


Log in to reply