Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. [solved] vectors and QGraphicsPixmapItem
Forum Updated to NodeBB v4.3 + New Features

[solved] vectors and QGraphicsPixmapItem

Scheduled Pinned Locked Moved Game Development
7 Posts 2 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marcius
    wrote on last edited by
    #1

    Hi everyone,

    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();
    scene->addItem(iter);
    }
    @

    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;
    card->SetCard(1,1);
    card->setPixmap(QPixmap("/card set/h7.gif"));
    scene->addItem(card);
    @
    it works fine.

    I don't understand what I do wrong.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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 *>

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Marcius
        wrote on last edited by
        #3

        Got it.

        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?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That's it, you're right

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Marcius
            wrote on last edited by
            #5

            Much appreciated!

            And I came to realize how poorly written my code is..

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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 :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Marcius
                wrote on last edited by
                #7

                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!

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved