I'm trying to connect two objecs, the first QPushButton
and the second one inherits QGraphicsTextItem
. I have an issue and i do not know how to fix it. Tell me what could it be?
costofbet.h
#ifndef COSTOFBET_H
#define COSTOFBET_H
#include <QGraphicsTextItem>
class CostOfBet : public QGraphicsTextItem
{
Q_OBJECT
private:
int bet;
public:
explicit CostOfBet(QGraphicsTextItem * parent = 0);
int getBet()const;
void setBet(int _bet);
void increaseBet();
void decreaseBet();
public slots:
void increaseBetSlot();
void decreaseBetSlot();
};
#endif // COSTOFBET_H
costofbet.cpp
#include "costofbet.h"
#include <QFont>
CostOfBet::CostOfBet(QGraphicsTextItem * parent)
: QGraphicsTextItem()
{
bet = 0;
setPlainText(QString("CSTOFBET:\n") + QString::number(bet) + QString(" $"));
setDefaultTextColor(Qt::darkGreen);
setFont(QFont("carocalcy", 16));
}
int CostOfBet::getBet() const
{
return bet;
}
void CostOfBet::setBet(int _bet)
{
if(_bet < 0)
return;
bet = _bet;
}
void CostOfBet::increaseBet()
{
bet += 5;
}
void CostOfBet::decreaseBet()
{
if(bet - 5 < 0)
return;
bet -= 5;
}
void CostOfBet::increaseBetSlot()
{
increaseBet();
}
void CostOfBet::decreaseBetSlot()
{
decreaseBet();
}
game.h
#ifndef GAME_H
#define GAME_H
#include <QGraphicsScene>
#include <QGraphicsView>
class Game : public QGraphicsView
{
private:
QGraphicsScene * scene;
protected:
virtual void wheelEvent (QWheelEvent * event);
public:
Game(QWidget *parent = 0);
~Game();
};
#endif // GAME_H
game.cpp
#include "game.h"
#include <QGraphicsRectItem>
#include <QGraphicsWidget>
#include <QGraphicsGridLayout>
#include <QEvent>
#include <QDebug>
#include "costofbet.h"
#include <QPushButton>
Game::Game(QWidget *parent)
: QGraphicsView(parent)
{
scene = new QGraphicsScene();
//create 3 items to place game mechanism
QGraphicsRectItem * top = new QGraphicsRectItem;
QGraphicsRectItem * middle = new QGraphicsRectItem;
QGraphicsRectItem * bottom = new QGraphicsRectItem;
top->setRect(0,-550,400,50);
middle->setRect(0,-500,400,400);
bottom->setRect(0,-100,400,100);
scene->addItem(top);
scene->addItem(middle);
scene->addItem(bottom);
//add money, bet, jackpot to the top rectitem
MoneyLeft * money = new MoneyLeft;
money->setPos(0,-550);
scene->addItem(money);
CostOfBet * mybet = new CostOfBet;
mybet->setPos(134,-550);
scene->addItem(mybet);
//add the buttons to the bottom sector
QPushButton * incrButton = new QPushButton;
QPushButton * decrButton = new QPushButton;
incrButton->setText("Increase bet");
decrButton->setText("Decrease bet");
incrButton->setGeometry(0,-99,100,50);
decrButton->setGeometry(0,-49,100,50);
scene->addWidget(incrButton);
scene->addWidget(decrButton);
//make the bet work
QObject::connect(incrButton, SIGNAL(clicked(bool)), mybet, SLOT(increaseBetSlot()));
QObject::connect(decrButton, SIGNAL(clicked(bool)), mybet, SLOT(decreaseBetSlot()));
//show the view
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFixedSize(400, 550);
setScene(scene);
show();
}
void Game::wheelEvent(QWheelEvent * event)
{
if (event->type() == QEvent::Wheel)
return;
return;
}
Game::~Game()
{
}
How to connect this slots and signals?
QObject::connect(incrButton, SIGNAL(clicked(bool)), mybet, SLOT(increaseBetSlot()));
QObject::connect(decrButton, SIGNAL(clicked(bool)), mybet, SLOT(decreaseBetSlot()));
The compiler points to this lines
CostOfBet::CostOfBet(QGraphicsTextItem * parent)
: QGraphicsTextItem() //an issue
{
.....;
}
and says error: undefined reference to vtable for CostOfBet
.
How to fix this? Any guess would be nice.