Results 1 to 20 of 21

Thread: Cannot create a QAbstractItemModel::createIndex(r,c),

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Cannot create a QAbstractItemModel::createIndex(r,c),

    I have a function to retrieve data from my model.
    I want to call it using row,col (r,c) set by me.
    Qt Code:
    1. return a_model->data(QAbstractItemModel::createIndex(r,c),Qt::DisplayRole);
    To copy to clipboard, switch view to plain text mode 
    Ok, I get
    error: cannot call member function 'QModelIndex QAbstractItemModel::createIndex(int, int, void*) const' without object

    Any idea ?

  2. #2
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cannot create a QAbstractItemModel::createIndex(r,c),

    Yes, re-read the error message and you might then realise that you cannot just call QAbstractItemModel::createIndex. You need an object of type QAbstractItemModel to call that method...
    Last edited by agarny; 20th April 2011 at 11:02.

  3. #3
    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: Cannot create a QAbstractItemModel::createIndex(r,c),

    He won't call it because it's a protected method But that's a completely different issue...
    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.


  4. #4
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cannot create a QAbstractItemModel::createIndex(r,c),

    Maybe I cannot call model::data ????

  5. #5
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cannot create a QAbstractItemModel::createIndex(r,c),

    Quote Originally Posted by tonnot View Post
    Maybe I cannot call model::data ????
    As Wysota said, it's a protected method, so...

  6. #6
    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: Cannot create a QAbstractItemModel::createIndex(r,c),

    Quote Originally Posted by agarny View Post
    As Wysota said, it's a protected method, so...
    But this is irrelevant in this case, the compiler complains about something else. Only when he fixes the current problem the compiler will complain it's a protected method. Which then will lead to a real question - why is this method protected and should it be used in this context. So let's go one step at a time and let tonnot learn by his own mistakes (again).

    @tonnot: I would really recommend you take some cash, go to a bookstore, buy some decent book on C++ and read it WITH UNDERSTANDING.
    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.


  7. #7
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cannot create a QAbstractItemModel::createIndex(r,c),

    Quote Originally Posted by wysota View Post
    But this is irrelevant in this case, the compiler complains about something else. Only when he fixes the current problem the compiler will complain it's a protected method. Which then will lead to a real question - why is this method protected and should it be used in this context. So let's go one step at a time and let tonnot learn by his own mistakes (again).
    You are definitely more patient than I am!

  8. #8
    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: Cannot create a QAbstractItemModel::createIndex(r,c),

    Quote Originally Posted by agarny View Post
    You are definitely more patient than I am!
    Not really. I just don't want to go through the same issue in two days when tonnot decides to use a regular method as a static one again. And since we had an argument when I called him an immature programmer, I'm treating him as a matrure programmer now assuming he does know what he is doing and that he indeed does know C++. Maybe finally he will decide he needs help improving his C++ skills.
    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.


  9. #9
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cannot create a QAbstractItemModel::createIndex(r,c),

    Quote Originally Posted by wysota View Post
    Not really. I just don't want to go through the same issue in two days when tonnot decides to use a regular method as a static one again.
    Let me rephrase then: you are definitely more optimistic than I am!

  10. #10
    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: Cannot create a QAbstractItemModel::createIndex(r,c),

    Or more sarcastic
    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.


  11. #11
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Cannot create a QAbstractItemModel::createIndex(r,c),

    Thanks everybody and excuse me for my poor english and my poor c++ knowlegde.
    I understand your explanations

    And I'm glad to make you more fun with the task of addressing the forum

  12. #12
    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: Cannot create a QAbstractItemModel::createIndex(r,c),

    Just spend an hour a day for two months learning C++ (and I mean learning and not doing tutorials or copying code) and you will stop giving us reasons to answer the way we do.
    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.


  13. #13
    Join Date
    May 2012
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cannot create a QAbstractItemModel::createIndex(r,c),

    Hello, I know this is an old thread, but I came across this same error message and I will lay this right out up front....I am an inexperienced programmer!!
    I know help was not given to the OP because the claim was they had experience and this error suggested otherwise, but if someone could help me(an inexperienced programmer) out, I would greatly appreciate it.

    I learn best by trying and failing. Well I tried, and failed, and got this error message. And then, created an object and got the next error, "its protected!!". So Can someone help explain why some times you can use class::method (QString::Number()) and it works, and some times QTreeWidget::itemFromIndex(), you cant?

    I have read many C++ books, but they all seem to do the same thing. They start out teaching basics, loops, conditional statements, etc, then touch on classes, and then BAM, your in over your head. This is how you build a car....you take some nuts and bolts, arrange them in a certain order, and BAM you have a car....and your left scratching your head, well how come that nut and bolt went here and not there, and what happened to everything else. (poor example, but I hope it makes sense).

    Thanks.

  14. #14
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cannot create a QAbstractItemModel::createIndex(r,c),

    Seriously?! Read the first few paragraphs of:

    http://www.cplusplus.com/doc/tutorial/classes/

Similar Threads

  1. QTreeView with QAbstractItemModel
    By Fletcher in forum Qt Programming
    Replies: 4
    Last Post: 10th December 2009, 23:02
  2. qAbstractItemView, QAbstractItemModel...
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 18th May 2009, 09:22
  3. Replies: 4
    Last Post: 1st May 2009, 11:00
  4. Once more : QAbstractItemModel woes
    By Valheru in forum Qt Programming
    Replies: 10
    Last Post: 15th January 2008, 10:44
  5. Help needed with QAbstractItemModel
    By Harvey West in forum Qt Programming
    Replies: 11
    Last Post: 27th November 2006, 12:06

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.