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. QQmlListProperty constructor doesn't accept my arguments
Forum Updated to NodeBB v4.3 + New Features

QQmlListProperty constructor doesn't accept my arguments

Scheduled Pinned Locked Moved QML and Qt Quick
qqmllistpropert
16 Posts 3 Posters 5.6k 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.
  • D Offline
    D Offline
    dasRicardo
    wrote on last edited by dasRicardo
    #2

    OK, i did nearly the same as you here an working example.

    // declare
    Q_PROPERTY(QQmlListProperty<QObject> fields READ fields)
    //getter
    QQmlListProperty<QObject> fields();
    //member to fill with data
    QList<QObject*> m_fields;
    
    //implementation of the getter
    QQmlListProperty<Object> YourClass::fields() {
            return QQmlListProperty<Object>(this, this->m_fields);
          }
    

    Thats all for me. I have to replace MyCustomClass with QObject but my custom class derived from QObject this is needed see documentation of QQmlListProperty

    [edit: updated coding tags SGaist]

    **Sorry for my english :)

    PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT&#x27;S SOLVED.**

    1 Reply Last reply
    0
    • T Offline
      T Offline
      themts
      wrote on last edited by
      #3

      @SGaist: Thanks

      @dasRicardo:
      so you say I have to replace

      QQmlListProperty<TestItem>
      

      with

      QQmlListProperty<QObject>
      

      even if TestItem is derived from QObject? Why?

      mts

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dasRicardo
        wrote on last edited by dasRicardo
        #4

        Hmm,

        my biggest misstake was my CustomClass have a namespace so if you use namespace also u need to do this:

        Q_PROPERTY(QQmlListPropertyfull::namespace::CustomClass fields READ fields)

        **Sorry for my english :)

        PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT&#x27;S SOLVED.**

        1 Reply Last reply
        0
        • T Offline
          T Offline
          themts
          wrote on last edited by
          #5

          I don't use a namespace in my class.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dasRicardo
            wrote on last edited by dasRicardo
            #6

            No i dont want to say u need to replace your custom class with QObject sorry my english is horrible. I did this for this example because in my production code i have to use my custom class so this doesn't make sense here to post.

            Not enough info to help you, i doesn't know how your TestItem class looks like

            **Sorry for my english :)

            PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT&#x27;S SOLVED.**

            1 Reply Last reply
            0
            • T Offline
              T Offline
              themts
              wrote on last edited by themts
              #7

              TestItemClass:

              class TestItem : public NChartRenderItem
              {
                  Q_OBJECT    
              private:
                  QOpenGLBuffer *m_vertexBuffer = NULL;
              
              public:
                  TestItem();
                  ~TestItem();
              
                  // NChartRenderItem interface
              public:
                  bool createVertexBuffer(int bufferSize);
                  bool renderItem();
              };
              

              NChartRenderItem-Class:

              class NChartRenderItem : public QObject
              {
                  Q_OBJECT
              public:
                  explicit NChartRenderItem(QObject *parent = 0);
                  ~NChartRenderItem();
              
                  virtual bool createVertexBuffer(int bufferSize) = 0;
                  virtual bool renderItem() = 0;
              
              signals:
              
              public slots:
              };
              
              1 Reply Last reply
              0
              • D Offline
                D Offline
                dasRicardo
                wrote on last edited by dasRicardo
                #8

                Hmm can u show me the constructor implementation?

                **Sorry for my english :)

                PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT&#x27;S SOLVED.**

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  themts
                  wrote on last edited by
                  #9

                  At this moment the constructors are just empty.

                  TestItem::TestItem()
                  {
                  }
                  
                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dasRicardo
                    wrote on last edited by dasRicardo
                    #10

                    @themts said:

                    QQmlListProperty<TestItem> TestClass::lstTestItems() const
                    {
                    return QQmlListProperty<TestItem>(this, 0, &TestClass::count_lstTestItems, &TestClass::at_lstTestItems);
                    }

                    Why this?

                    In my impelentation it looks diffrent.

                    <pre><code>
                    //implementation of the getter
                    QQmlListProperty<Object> YourClass::fields() {
                    return QQmlListProperty<Object>(this, this->m_fields);
                    }
                    </code></pre>

                    **Sorry for my english :)

                    PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT&#x27;S SOLVED.**

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      themts
                      wrote on last edited by
                      #11

                      QQmlListProperty has 3 constructor. I'm using this one:
                      http://doc.qt.io/qt-5/qqmllistproperty.html#QQmlListProperty-4

                      That way I can use it as a "virtual" list.
                      Anyway, even if I use it your way - which is not recommended - it shows the same error.
                      "Generally this constructor should not be used in production code, as a writable QList violates QML's memory management rules. However, this constructor can be very useful while prototyping."

                      QList<TestItem*> m_lstTestItems;
                      
                      return QQmlListProperty<TestItem>(this, this->m_lstTestItems);
                      
                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dasRicardo
                        wrote on last edited by
                        #12

                        OK, thanks for your hints. I will definitely change this. I saw this in different sample codes. But my c++ and QT knowledge is very nooby :) Sorry that i can't help u. Not really an idea.

                        **Sorry for my english :)

                        PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT&#x27;S SOLVED.**

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          dasRicardo
                          wrote on last edited by dasRicardo
                          #13

                          Can u show me the constructor implementation of your NChartRenderItem class?

                          **Sorry for my english :)

                          PLEASE ADD [SOLVED] TO YOUR THREAD TITLE IF IT&#x27;S SOLVED.**

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            themts
                            wrote on last edited by themts
                            #14

                            I really don't understand why it's not working.
                            I even tried to use Q_PROPERTY(QQmlListProperty<QObject> ... -> same result

                            I don't get it. The error-message (C2665) seems to be wrong as well: it says 5 overloads.
                            Actually there are only 4.

                            Does anyone has an idea?
                            Btw. I want to use QQmlListProperty as a datamodel for a listview.

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              swegmann
                              wrote on last edited by
                              #15

                              Can you show us the full error message of the compiler for the case where you give it the count and at functions? I think there might be some helpfull information about this issue.

                              1 Reply Last reply
                              0
                              • T themts

                                Hi,

                                I'm doing my first steps with QQmlListProperty.
                                Unfortunately I'm not able to create such list :-(

                                header:

                                class TestClass : public QQuickFramebufferObject    
                                {
                                    Q_OBJECT
                                    Q_PROPERTY(QQmlListProperty<TestItem> lstTestItems READ lstTestItems)
                                
                                private:
                                    static int count_lstTestItems(QQmlListProperty<TestItem> *list);
                                    static TestItem* at_lstTestItems(QQmlListProperty<TestItem> *list, int index);
                                
                                public:
                                    QQmlListProperty<TestItem> lstTestItems() const;
                                }
                                

                                source:

                                QQmlListProperty<TestItem> TestClass::lstTestItems() const
                                {              
                                    return QQmlListProperty<TestItem>(this, 0, &TestClass::count_lstTestItems, &TestClass::at_lstTestItems);
                                }
                                

                                Error:
                                error: C2665: "QQmlListProperty<TestItem>::QQmlListProperty": Durch keine der 5 Überladungen konnten alle Argumenttypen konvertiert werden.

                                What am I missing here?

                                Thanks!
                                mts

                                P.S. how can I mark parts of my post as code?

                                [edit: Added missing coding tags three back sticks to start and three to end SGaist]

                                T Offline
                                T Offline
                                themts
                                wrote on last edited by themts
                                #16

                                solved :-)
                                no one saw it ;-)

                                public:
                                    QQmlListProperty<TestItem> lstTestItems() const;
                                

                                this can't be const. Thats it.

                                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