Results 1 to 3 of 3

Thread: [qt4,win,g++] model/view programming: selection, internal pointer wrong ?!

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default [qt4,win,g++] model/view programming: selection, internal pointer wrong ?!

    hi,
    i get a selection model from a treeview and connect signal
    selectionChanged to the following method:

    Qt Code:
    1. void
    2. Container_Widget::selectionChanged(const QItemSelection& selected,
    3. const QItemSelection& deselected)
    4. {
    5.  
    6. printf("<Container_Widget::selection changed()>\n");
    7. fflush(stdout);
    8.  
    9. QModelIndexList indexlist = selected.indexes();
    10. QListIterator<QModelIndex> it(indexlist);
    11.  
    12. while(it.hasNext()) {
    13.  
    14. QModelIndex modelindex = it.next();
    15.  
    16. if(!modelindex.isValid()) {
    17. printf("Container_Widget::selectionChanged() : model index not valid \n");
    18. fflush(stdout);
    19. continue;
    20. }
    21.  
    22. printf("Container_Widget::selectionChanged() : row = %d, col = %d \n",
    23. modelindex.row(), modelindex.column() );
    24. fflush(stdout);
    25.  
    26. Container_ModelItem* item
    27. = static_cast<Container_ModelItem*>(modelindex.internalPointer());
    28.  
    29. ... call some method of item -> segfault !!
    30.  
    31. }
    32.  
    33. printf("</Container_Widget::selection changed()>\n");
    34. fflush(stdout);
    35.  
    36. }
    To copy to clipboard, switch view to plain text mode 

    the problem is that the internal pointer of the model index
    cannot be of class Container_ModelItem,
    since if i call a method of this class the program crashes.
    i checke already all methods of the model which return a QModelIndex,
    i could'nt find a mistake there.
    where is the mistake?

    bets regards,
    jh

  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: [qt4,win,g++] model/view programming: selection, internal pointer wrong ?!

    First of all use dynamic_cast instead of static one. And second of all, it's not possible to help you without seeing the source of the model, at least its index() method.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    84
    Thanks
    7
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [qt4,win,g++] model/view programming: selection, internal pointer wrong ?!

    i already found the problem. i used a sorting proxy model which was
    invalid.

    thanx.

    jh

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.