Results 1 to 3 of 3

Thread: Delegate not passing the correct index for the model

  1. #1
    Join Date
    Aug 2012
    Posts
    6
    Qt products
    Qt4
    Platforms
    Maemo/MeeGo

    Default Delegate not passing the correct index for the model

    I have a some code like follows, when i click on a list item in the view, there is a runtime error with model[index], i cant figure out why, in qt creator index is also highlighted blue & italicized like javascript:

    somemodelpage.qml

    Qt Code:
    1. page{
    2. listview {
    3. id: itemview
    4. delegate: itemdelegate { }
    5. model: cppmodel
    6.  
    7. function delegateClicked(index) {
    8. model.folder = model[index].name;
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    itemdelegate.qml
    Qt Code:
    1. Item {
    2. id: root
    3. ...
    4. mousearea {
    5. onclicked: root.ListView.view.delegateClicked(index)
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by balisingh; 26th October 2012 at 04:41.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Delegate not passing the correct index for the model

    The problem probably is in the C++ model.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: Delegate not passing the correct index for the model

    I don't understand how delegateClicked can be written not with a formal parameter, but with an actual argument. I think you might try removing the delegateClicked function and Item's onClicked entirely, and writing itemdelegate { onClicked: model.folder = ... }.

Similar Threads

  1. Proxy model, index mapping.
    By wojtekw in forum Qt Programming
    Replies: 14
    Last Post: 7th January 2016, 08:09
  2. Mapping Index from View to Model
    By toodles in forum Newbie
    Replies: 1
    Last Post: 3rd July 2012, 19:37
  3. QFileSystemModel::remove not removing index from model
    By revorgm in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 09:24
  4. QDataWidgetMapper setting own model index
    By AlGaN in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2010, 16:34
  5. How to get index of a combobox delegate selection
    By vieraci in forum Qt Programming
    Replies: 12
    Last Post: 21st July 2009, 16:37

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.