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. List View using two elements

List View using two elements

Scheduled Pinned Locked Moved QML and Qt Quick
13 Posts 3 Posters 5.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
    thisisbhaskar
    wrote on last edited by
    #2

    Hi, can you clarify if memberSelectionCpp is a qml property exposed from C++ with setContextPropery or a C++ class exposed with qmlRegisterType?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dridk
      wrote on last edited by
      #3

      Could you explain more ? I didn't understand what you want.
      Why is it impossible to get all data and after send them to the listModel ?

      Nothing in Biology Makes Sense Except in the Light of Evolution

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chronoske
        wrote on last edited by
        #4

        oops, i missed some details..

        i used the setContextProperty, this is the code: @view->engine()->rootContext()->setContextProperty("memberSelectionCpp",selectLevel);
        @
        And the seen member of team 1 is "undefined"

        the fungsiReturnID is as follows:
        @QString memberSelect::fungsiReturnID(int index)
        {
        return soapResult.result->__ptr[index]->UserID;
        }
        @
        i used a gsoap to return ID from my dummy database
        it is possible to display the data if i inputted it manually, but just in case if my data got increasing, then it would get even harder to input them all manually, right? Any suggestion to fix it? Thanks.

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

          I tried this and got a run time error that script can not be used to specify ListElement property value. Can "TROLLS" help here?

          @chronoske, are you getting any qml run-time error?

          1 Reply Last reply
          0
          • C Offline
            C Offline
            chronoske
            wrote on last edited by
            #6

            nope, i didn't get any run-time error at all, the return string just doesn't show. that's all..

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

              @ ListElement { ListElement.objectName: memberSelectionCpp.fungsiReturnID(2); team: 1 }@

              I did not get whey are you using ListElement.objectname here?? where did you get this from?

              Should't it be something like
              @ListElement { name: memberSelectionCpp.fungsiReturnID(2); team: 1 }@

              may be I am wrong...

              1 Reply Last reply
              0
              • C Offline
                C Offline
                chronoske
                wrote on last edited by
                #8

                i tried using that trick as well, but instead it gives a warning "ListElement: cannot use script for property value
                ListElement { name: memberSelectionCpp.fungsiReturnID(2) ; team: 1 }"

                And when i try to type ListElement, the autocomplete shows only two options: deleteLater or objectName, so i picked the objectName, and the result is undefined. Could it be that i used the wrong syntax?

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

                  I think, with ListElement.objectName, you are trying to assign value to "objectName" property of the ListElement.

                  For back-ground about objectname, http://doc.qt.nokia.com/latest/qobject.html#objectName-prop

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    chronoske
                    wrote on last edited by
                    #10

                    i'm sorry, but could anyone explain more? My problem is that i can not insert strings that is being returned by a function in cpp into list view element. I have tried to look for sample codes but all that i found is the list view name that is inputted manually, and since i have quite some data, i don't think that it will be possible,, Help, anyone?

                    thank you

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

                      Looks like some good news for you.. You can do it..

                      @ListModel {
                      id: myModel
                      ListElement { name: "Bob"; team: 2 }
                      ListElement { name: "Jane"; team: 3 }

                             Component.onCompleted: {
                                  append({name:memberSelectionCpp.fungsiReturnID(2),team:1})
                             }
                          }
                      

                      @

                      If you want to insert your element in a different place, you can use insert function of ListModel.

                      But you need to make sure something from C++ side..

                      Make sure that "memberSelectionCpp" is made available to qml with setContextProperty before you set your qml file to QDeclarativeView. Otherwise above code does not work. Try and let us know if this works.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        chronoske
                        wrote on last edited by
                        #12

                        I still can't figured it how, so I guess I'll try to change the concept for my project. Thanks everyone!

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          thisisbhaskar
                          wrote on last edited by
                          #13

                          [quote author="chronoske" date="1310520896"]I still can't figured it how, so I guess I'll try to change the concept for my project. Thanks everyone![/quote]

                          It seems to work for me. What is the problem you are facing..

                          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