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. How do you pass in a parameter to create a class when the Q_PROPERTY parameter is QVariantList?

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 351 Views
  • 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.
  • M Offline
    M Offline
    mirro
    wrote on last edited by mirro
    #1

    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
    
    jsulmJ 1 Reply Last reply
    0
    • M mirro

      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
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved