×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Apr 2011
    Posts
    89

    New item can't display in ListView.

    When adding a new item in the ListView from UI, the item's name can't display.
    But if I flick on the ListView up and down, the name comes.

    Meantime, in delegate module, it says. "Unable to assign [undefined] to QString text" where "text" should display the item's “name"

    This is why? How to display it automatically?

    I've tried the sync() method of ListMode, but doesn't work.


    Code:
     Rectangle {
         color: "white"
         width: 200
         height: 300
    
         ListModel {
             id: fruitModel
             ListElement {
                 name: "Apple"
                 cost: 2.45
             }
         }
    
         ListView {
             anchors.fill: parent
             model: fruitModel
             delegate: Component {
                 ...
             }
    
             ListModel { id: listModel }
         }
     }
    Last edited by useryy2; 2012-02-18 at 08:55.

  2. #2
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    3,956

    Re: New item can't display in ListView.

    Adding item from UI means adding it from c++ or else? Also can you show how do you add the item

  3. #3
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: New item can't display in ListView.

    i will be also interested to see your code of delegate implementation.

  4. #4
    Super Contributor
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,037

    Re: New item can't display in ListView.

    If I add anything into the list model, list is automatically updated.

    check for: ListModel::append ( jsobject dict )

    are you doing something different?

  5. #5
    Regular Contributor
    Join Date
    Apr 2011
    Posts
    89

    Re: New item can't display in ListView.

    Basic code implementation is from "QtSDK\Examples\4.7\declarative\modelviews\listview\dynamiclist"

    And I have found the reason:
    When adding a ListElement , I will
    1) Create a new ListElement in Javascript.
    2) Insert/Append it.
    3) Update the element's "name"/"cost"

    As a result, in step 2, the UI changes. But for step 3, UI does not update.

    To workaround:
    1) Create an empty ListElement when the ListView is first created.
    2) Change the ListElement's "name" or "cost" according to input from UI
    3) Create a new empty ListElement Javascript.
    4) Append/Insert it for next round.

    For more: http://doc.qt.nokia.com/4.7-snapshot...icobjects.html

Similar Threads

  1. Checkbox toggles on clicking item in listview
    By mind_freak in forum [Archived] Qt Quick
    Replies: 8
    Last Post: 2011-11-07, 12:24
  2. How to access ListView current item data?
    By Sasler in forum [Archived] Qt Quick
    Replies: 1
    Last Post: 2011-11-03, 15:11
  3. ListView item removing problem
    By pippo2010 in forum [Archived] Qt Quick
    Replies: 0
    Last Post: 2011-02-25, 23:01
  4. How to get Listview selected item
    By amol_benare604 in forum Qt
    Replies: 1
    Last Post: 2010-11-18, 09:25
  5. How to Disable Command Button and list item on Listview for S40 devices
    By iworktech_kiran in forum Mobile Java General
    Replies: 3
    Last Post: 2008-08-29, 17:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •