Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:33:45+00:00 2026-06-09T15:33:45+00:00

I am implementing a card game, with a GUI, in C++, using Qt. I

  • 0

I am implementing a card game, with a GUI, in C++, using Qt.

I have a main.cpp, that create a window by calling the class Window in window.cpp. In window.cpp, we have a bunch of frames and other widgets that will later form the GUI.

Then there is the class Card in card.cpp, with infos about the cards. The class Deck, in deck.cpp, has the number of card of a certain type. Finally, gui_cards_kingdom.cpp constructs a widget from the image of the card (path in Card) and infos from card (also in Card). gui_cards_kingdom define a class that inherits from Widget, and contain an instance of Deck (to be able to pull the infos needed).

So far, so good. In window.cpp, I create an instance of Card, and put it in an instance of Deck, that I sent to Cards_kingdom (class in gui_cards_kingdom.cpp).

I get a segmentation fault when using QPixmap in gui_cards_kingdom.cpp at the line img->setPixmap(image)

The debugger tells me that the info is there, everything is in place, except when I use QPixmap to load the image of the card onto a label.

It is not the path, as I tested some simple code in main.cpp (see the commented out code in main.cpp). I went down to just img->setPixmap(image); just to be sure.

I am at the limit of my knowledge. I searched a lot, and did not find anything, therefore, I am asking you guys, what do you see in here, that I missed?

Thank you in advance, for your time, and your help,

-Béatrice

main.cpp:

#include <QtGui>
#include <window.h>

int main(int argc, char *argv[]){
QApplication app(argc, argv);

//QWidget fenetre;
//QLabel *label = new QLabel(&fenetre);
//label->setPixmap(QPixmap("Images/Cards/Base/village.jpg"));
//label->move(30, 20);
//    fenetre.show();

Window window;
window.show();
return app.exec();

}

card.h:

#ifndef CARD_H
#define CARD_H

#include <string>

class Card {
public:
    Card(int price, std::string info, std::string path, std::string id);
    int get_price();
    std::string get_info();
    std::string get_path();
    std::string get_id();
private:
    int price;
    std::string info;   /* Text on card     */
    std::string path;   /* Path to image    */
    std::string id;     /* Name/ID of card  */
};
#endif // CARD_H

card.cpp:

#include <card.h>

Card::Card(int a, std::string b, std::string c, std::string d){
    price = a;
    info  = b;
    path  = c;
    id    = d;
}

int Card::get_price(){
    return price;
}

std::string Card::get_info(){
    return info;
}

std::string Card::get_path(){
    return path;
}

std::string Card::get_id(){
    return id;
}

deck_kingdom.h:

#ifndef DECK_KINGDOM_H
#define DECK_KINGDOM_H

#include <card.h>

class Deck_kingdom {
public:
    Deck_kingdom(int size_deck, Card* card_type);
    int get_count();
    Card* get_card();
private:
    Card* card;
    int count;
};
#endif // DECK_KINGDOM_H

deck_kingdom.cpp:

#include <deck_kingdom.h>

Deck_kingdom::Deck_kingdom(int size_deck, Card *new_card){
    count = size_deck;
    card = new_card;
}

int Deck_kingdom::get_count(){
    return count;
}

Card* Deck_kingdom::get_card(){
    return card;
}

gui_cards_kingdom.h:

#ifndef GUI_CARDS_KINGDOM_H
#define GUI_CARDS_KINGDOM_H

#include <QtGui>
#include <QApplication>
#include <QFrame>
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QString>
#include <sstream>
#include <string>
#include <QPixmap>

#include <deck_kingdom.h>

#define CARD_HEIGHT 135
#define CARD_WIDTH  85

class Cards_kingdom : public QWidget {

public:
    Cards_kingdom(Deck_kingdom * input_deck);    /* Constructor  */

/*
 * Price and Counter are display in the same label, then are wrapped with Icon in a vertical layout, inside a frame.
 */
private:
    QLabel       *img;       /* Icon         */
    QLabel       *info;     /* Nb Cards left*/
    QVBoxLayout  *layout;    /* Layout       */
    QFrame       *pack;      /* Frame        */
    Deck_kingdom *deck;      /* Deck         */
};

#endif // GUI_CARDS_KINGDOM_H

gui_cards_kingdom.cpp:

#include <gui_cards_kingdom.h>
#include <iostream>

Cards_kingdom :: Cards_kingdom(Deck_kingdom * input_deck) : QWidget(){

    deck = input_deck;

    //DEBUG
    std:: cout << deck->get_card()->get_price() << std::endl;

    /* Convert "price" and "count" into string */
    std::ostringstream price, count;
    price << deck->get_card()->get_price();
    count << deck->get_count();
    std::string text_label ("$"+price.str()+" ("+count.str()+")");

    //QString test = QString::fromStdString(deck->get_card()->get_path());

    //img->setPixmap(QPixmap(test).scaled(CARD_WIDTH,CARD_HEIGHT,Qt::IgnoreAspectRatio, Qt::FastTransformation ));
    QPixmap image  = QPixmap("Images/Cards/Base/village.png");
    img->setPixmap(image); // THE PROBLEM IS HERE

    img->setToolTip(QString::fromStdString(deck->get_card()->get_info()));
    info->setText(QString::fromStdString(text_label));
    layout = new QVBoxLayout();
    layout->addWidget(img);
    layout->addWidget(info);
    pack->setLayout(layout);
    pack->setParent(this);

}

window.h :

#ifndef WINDOW_H
#define WINDOW_H

#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QFrame>
#include <gui_cards_kingdom.h>

class Window : public QWidget {
    public:
    Window();

    protected:
    QVBoxLayout *layout_1;
    QHBoxLayout *layout_2;
    QGridLayout *layout_3;
    QFrame *box_1;
    QFrame *box_2;
    QFrame *box_layout_2;
    QFrame *box_3;
    QFrame *box_4;
};
#endif // WINDOW_H

window.cpp:

#include <window.h>
#include <iostream>

Window::Window(){
    /* Window       */

    setFixedSize(900,700);
    move(10,10);


    layout_1 = new QVBoxLayout(this);       /* Global Vertical Column      */
    layout_2 = new QHBoxLayout;                /* Include Kingdom and Log     */
    layout_3 = new QGridLayout;                /* Matrix display Kingdom cards*/


    /* Kingdom cards box       */
    box_1 = new QFrame(this);
    box_1->setFrameShape(QFrame::StyledPanel);
    box_1->setGeometry(30, 20, 300, 300);
    box_1->setToolTip("box_1");
    box_1->setLayout(layout_3);

    Card * test_card = new Card(2,"Village: +2 Action, +1 Buy", "Images/Cards/Base/village.jpg", "Village");
    Deck_kingdom * test_deck = new Deck_kingdom(10, test_card);

    std::cout << "Here 2a" << std::endl;
    Cards_kingdom * test_gui = new Cards_kingdom(test_deck);
    std::cout << "Here 2b" << std::endl;

    layout_3->addWidget(test_gui,0,0);

    std::cout << "Here 2" << std::endl;
    /* Log */
    box_2 = new QFrame(this);
    box_2->setFrameShape(QFrame::StyledPanel);
    box_2->setGeometry(340, 20, 300, 300);
    box_2->setToolTip("box 2");

    std::cout << "Here 2" << std::endl;

    layout_2->addWidget(box_1);
    layout_2->addWidget(box_2);

    box_layout_2 = new QFrame(this);
    box_layout_2->setLayout(layout_2);

    std::cout << "Here 2" << std::endl;
    /* Player Board*/
    box_3 = new QFrame(this);
    box_3->setFrameShape(QFrame::StyledPanel);
    box_3->setGeometry(30, 350, 650, 100);

    /* Chat room*/
    box_4 = new QFrame(this);
    box_4->setFrameShape(QFrame::StyledPanel);
    box_4->setGeometry(30, 460, 650, 50);


    layout_1->addWidget(box_layout_2);
    layout_1->addWidget(box_3);
    layout_1->addWidget(box_4);

    setLayout(layout_1);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:33:46+00:00Added an answer on June 9, 2026 at 3:33 pm

    My C++ sucks, but I know PyQt4, so here we go…

    Are you sure you are initializing the QLabel pointer in your constructor?

    Cards_kingdom :: Cards_kingdom(Deck_kingdom * input_deck) : QWidget(){
        ...
        img = new QLabel;
        QPixmap image  = QPixmap("Images/Cards/Base/village.png");
        img->setPixmap(image); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing a card game. In this game I have a Board that is
I am currently implementing a Deck class that represents a 52 card playing deck.
I'm implementing a card game in C. There are lots of types of cards
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
I recently wrote a Java playing card game and have all the game logic
implementing publishActivity in PHP using the REST API using this code: $activity = array(
Implementing a custom membership provider, there are certain properties such as MinRequiredPasswordLength that only
When implementing a hash table using a good hash function (one where the probability
Before implementing j_security_check using MySQL realm authentication in my web app. I had the
We are looking at implementing a card-reader program for a integrated computer. The computer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.