[solved] vectors and QGraphicsPixmapItem
I'm facing yet another issue which I'm struggling with.
I have a vector, vector<Card> player, where Card is a class with its suit, rank and inherits QGraphicsPixmapItem. Let's say the vector has 5 Card items with their suits, ranks and pixmaps set.
for (vector<Card>::iterator iter = player->begin();
iter != player->end(); ++iter)
qDebug() << iter->GetSuit() << iter->GetRank();
Here, I successfully get suits and ranks, but cannot add object to the scene. I get en error: "no suitable conversion function from "std::_Vector_iterator<std::_Vector_val<std::_Simple_types<Card>>>" to "QGraphicsItem *" exists"
If I do something like this:
Card * card = new Card;
it works fine.
I don't understand what I do wrong.
vector<Card> implies that you can copy Card which is not the case since it's a QGraphicsPixmapItem. You can however use vector<Card *> or QVector<Card *>
So just to double check with you (because I'm about to rewrite quite a few bits of my code), when I use something like Card card, vector<card>, card = card2 etc - all of this would create a copy, which in turn generates that error that I'm getting?
That's it, you're right
And I came to realize how poorly written my code is..
Learning curve ;-)
Time to clean and refactor, and it's something you'll do several times in your carrier :)
If this answers your question, please update the thread title to solved so other forum users may know a solution has been found :)
I know, and I do enjoy learning these things. I just wish I would spend a little less time coping with all sorts of errors and more time on actual coding :) But I guess that's a part of it too.
Well, just finished rewriting the code. All I have now is a bucketload of pointers and references and got rid of those errors I previously had. All thanks to you!