Page 1 of 2 12 LastLast
Results 1 to 20 of 21

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

  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/

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

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

    well I appreciate the link. As I am still learning, it seems my problem is that of a design issue. Proper ways to design classes. Perhaps this comes from many years of experience programming and gaining understanding of just how everything works together. I am not there yet.

  16. #16
    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),

    The problem is not a design issue but rather lack of knowledge regarding how the hammer (i.e. c++) works.
    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.


  17. #17
    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),

    With all due respect to changedsoul, I think he first and foremost needs to learn how to read and understand what he reads. I mean, I cannot believe that the many (!?) C++ books he read don't mention anything about class access specifiers.

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

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

    Its not that what I read does not mention or teach about classes and access specifiers, its that they way its presented is never in a way that makes any sense to me. As an example, I am a cnc machinist presently. To explain my point about the books teaching c++, would be like me saying "Here is a machine, it can do this and this and this, and has these buttons", but that doesn't tell you how to actually develop anything on it. It takes time and learning how to properly use the tool. So a c++ book can tell me what a class can contain, but I find little info "for my understanding" how to actually put it into practice, how it all fits together and why. And reading a book front to back does nothing for me because if I do not use it repeatidly, I most likely will forget it....

  19. #19
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

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

    Here's the simplified rules for using the public, protected, and private access modifiers:


    • Public variables or methods are freely available from both inside and outside of your class
    • Protected variables or methods are available to your class or any class that subclasses your class
    • Private variables or methods are only available to your class implementation


    So generally, people make all of the class variables private, as well as methods that are not intended to be used by people using your class. Public should be used for methods you design that are intended to provide the interface for your class (how programmers interact with your class). Protected is a more advanced topic that you would implement for your class if it's intended that developers subclass your base class, etc.

    There's more to it than what I've written here, but this should get you started.

  20. #20
    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 changedsoul View Post
    Its not that what I read does not mention or teach about classes and access specifiers, its that they way its presented is never in a way that makes any sense to me. As an example, I am a cnc machinist presently. To explain my point about the books teaching c++, would be like me saying "Here is a machine, it can do this and this and this, and has these buttons", but that doesn't tell you how to actually develop anything on it. It takes time and learning how to properly use the tool. So a c++ book can tell me what a class can contain, but I find little info "for my understanding" how to actually put it into practice, how it all fits together and why. And reading a book front to back does nothing for me because if I do not use it repeatidly, I most likely will forget it....
    Keeping to your example, what you are trying to do is that having seen a picture of a machine in a store window you start building an airplane and you are frustrated there are no tutorials how to build a plane without posessing any engineering skills. Considering that millions of people managed to grasp how C++ works, it is possible to achieve. You just have to do it before trying to do something complex with it.

    You cannot expect every C++ feature you encounter to be explained to you by jefftee. I assure you he will eventually lose patience as well.
    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.


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.