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

How do you pass in a parameter to create a class when the Q_PROPERTY parameter is QVariantList?



  • Is the following way ok?How do I change the WRITE method?

    Reader* p = new Reader("123","456","789");
    
    #ifndef READER_H
    #define READER_H
    #include <QObject>
    #include <QVariantList>
    class Reader: public QObject
    {
        Q_OBJECT
        Q_PROPERTY(QVariantList record READ record WRITE setRecord NOTIFY recordChanged)
    public:
        Reader();
    
        QVariantList record() const; 
       {
            return record_;
       }
        Q_INVOKABLE void doSomething()const;
    
    public slots:
        void setRecord(const QVariantList & value);
        {
        
            if (record_ == value)
        
                return;
        
            record_ = value;
        
            emit recordChanged();
        
        }
    public:
        QVariantList record_;
    signals:
        void recordChanged();
    };
    #endif // READER_H
    

  • Qt Champions 2019

    @mirro Your Reader class does not have a constructor taking 3 parameters, so how is this going to work? To pass parameter to constructor you need a constructor taking these parameters.


  • Qt Champions 2019

    @mirro Your Reader class does not have a constructor taking 3 parameters, so how is this going to work? To pass parameter to constructor you need a constructor taking these parameters.


Log in to reply