Results 1 to 4 of 4

Thread: why this program is not working

  1. #1
    Join Date
    Apr 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default why this program is not working

    can anyone tell why this program is not working?
    am not able to see the directory structure.
    (from the printf's i could make out that is is not calling parent and data functions. this code doesnt contains printfs)

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class TestModel : public QAbstractItemModel
    4. {
    5. public:
    6. QDirModel *model;
    7. TestModel()
    8. {
    9. model = new QDirModel();
    10. }
    11.  
    12. QVariant data(const QModelIndex &index, int role) const
    13. {
    14. return model->data(index, role);
    15. }
    16.  
    17. QModelIndex index(int row, int column, const QModelIndex &parent) const
    18. {
    19. return model->index(row, column, parent);
    20. }
    21.  
    22. QModelIndex parent(const QModelIndex &index) const
    23. {
    24. return model->parent(index);
    25. }
    26.  
    27. int rowCount(const QModelIndex &parent) const
    28. {
    29. return model->rowCount(parent);
    30. }
    31.  
    32. int columnCount(const QModelIndex &parent) const
    33. {
    34. return model->columnCount(parent);
    35. }
    36. };
    37.  
    38. int main(int a, char** b)
    39. {
    40. QApplication app(a, b);
    41. TestModel *mod = new TestModel;
    42. QTreeView view;
    43. view.setModel(mod);
    44. view.show();
    45. return app.exec();
    46. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

  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: why this program is not working

    The index contains a pointer to the model and it has to match the actual model that is using it, so if you want to pass the index you get to another model, you have to build a new index that references this another model and not yours. And of course your index() and parent() implementations are invalid because of the same reason.

  3. #3
    Join Date
    Apr 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: why this program is not working

    Thanks Wysota,

    but i have no idea as how to build new index or map to another model index. Could you give any reference doc which is explaining this? How difficulty it is?

  4. #4
    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: why this program is not working

    Call the model's index() method with appropriate parameters. By the way, I don't know what you are doing, but maybe using QAbstractProxyModel would be easier?

Similar Threads

  1. Replies: 2
    Last Post: 28th March 2008, 17:03
  2. Replies: 19
    Last Post: 21st January 2008, 09:13
  3. Version setting in QT Program
    By sabeesh in forum Qt Programming
    Replies: 4
    Last Post: 24th October 2007, 12:07
  4. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19
  5. program for working with Data Base(i need it)
    By banakil in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 22:58

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.