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. [SOLVED] QQmlListProperty and append, at, clear, count - how to use them?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QQmlListProperty and append, at, clear, count - how to use them?

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 2 Posters 4.1k 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.
  • T Offline
    T Offline
    thEClaw
    wrote on last edited by
    #1

    So "here":http://doc.qt.io/qt-5/qqmllistproperty.html you can see QQmlListProperty. I set everything up (list of QObjects, accessible from QML) and have no idea how to call the methods "clear" etc. (yes, I handed over the pointers) from within QML. I would highly appreciate some clear instructions.

    Also a very frustrated note on QML - I suggest not reading it^^: "Designing" my first window with about 2.5 buttons in it took as long as writing the approximately 2000 lines of C++ code backing up that window - the documentation is full of errors, in most cases way too brief and incomplete (I have been spoiled by Qts documentation, I admit), the language seems completely non-intuitive to me since I have to constantly look up ever-changing properties which then are described in less than ten words, without existing (or linked) examples nearby (and if there are any, they are faulty)...
    I was really looking forward to QML, but after this little project is done, I will probably go back to Qt and wait for its deformed step-step-stepbrother to mature a little bit.
    (I just spend several hours trying to call the "clean()"-method on my QObject-list in QML, I apologize for all the brain-damage I must have taken.)

    PS: Thanks in advance for any kind of help. :)

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      Have you tried setting your list property equal to @[]@ (an empty javascript array). The idea behind QQmlListProperty is enable it to have an interface closely resembling that of a javascript array.

      Hang in there, there is a steep learning curve, but once you've gotten through it you won't want to go back to QWidget :).

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

        Well, that does something - thanks so far :) . But now the program crashes when I "empty" my list (I have to assume that's what happens, even though I can't see it before the crash).

        I am displaying the lists items in a ListView - it seems that doesn't get updated when I clear the list. Do you maybe have another hint to give me? I am pretty sure there is no ListView.clear(), I would have found that during my struggles yesterday. ;)

        EDIT: I now know how to prevent the crash, but again the solution seems super-non-intuitive:
        Instead of calling "myobject.mycustomQmlListProperty = []", which crashes the program, I have to call "ListView.model = []", even though I also set "ListView.model = myobject.mycustomQmlListProperty" not long before. This kind of fragile behavior is what puts me off about QML.

        Thanks again for the help, I will mark this as solved (and probably open up more threads soon :( ).

        PS:
        Just to answer more of the initial question:

        model.at(i) is accessed via model[i] (makes sense)
        model.count() can be accessed via model.length
        model.append() ... well, I have no idea - a couple more weeks with QML and I might know!

        1 Reply Last reply
        0
        • T Offline
          T Offline
          t3685
          wrote on last edited by
          #4

          I am not a big fan of QQmlListProperty myself. I prefer to make QAbstractItemModels when I need models for my list views. Only in very specific cases will I resort to QQmlListProperty.

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

            I read about that, and that seems to be a completely different approach. Had I read about it before having spent fifty hours with QQmlListProperty, I probably would have chosen that route instead (especially since the coding would have been familiar to me).
            However, by now I am too deep into QQmlListProperty to just quit.

            Do you know of any minimal (while fully functional) examples of how to use a QAbstractItemModel from QML? Or maybe you happen to at least know some buzzwords I can feed into google?

            1 Reply Last reply
            0
            • T Offline
              T Offline
              t3685
              wrote on last edited by
              #6

              Have you read these pages?

              http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html
              http://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html

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

                I've seen the pages but skipped over the "model"-part - thanks for the link, I'll have a look. Maybe I will need to know how to circumvent using QQmlListProperty in the future. ;)

                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