Hello all.
I'm very new to Qt but I'm extremely impressed with several aspects of it, especially the documentation.
I'm not an expert programmer (more of a hobbyist), so please feel very free to correct me.
I'm writing a tic-tac-toe game. I've got the game engine itself working, and I'm trying to wrap it up in a nice GUI.
One aspect of the game is going to be a grid of buttons representing the board. When a button is clicked, I want a signal to be emitted witht he coordinates of the button.
Here's what I've got:
#ifndef UISPOT_HPP
#define UISPOT_HPP
#include <QPushButton>
#include <QIcon>
#include "spot.hpp"
namespace ttt {
Q_OBJECT
private:
Spot spot_;
slots:
void buttonClicked();
signals:
void clickedAt( const Coord &coord );
public:
UISpot
( const Spot
&spot,
QWidget *parent
) : spot_( spot ) {
connect( this, SIGNAL( clicked() ),
this, SLOT( buttonClicked() ) );
}
};
}
#endif // UISPOT_HPP
#ifndef UISPOT_HPP
#define UISPOT_HPP
#include <QPushButton>
#include <QIcon>
#include "spot.hpp"
namespace ttt {
class UISpot : public QPushButton {
Q_OBJECT
private:
Spot spot_;
slots:
void buttonClicked();
signals:
void clickedAt( const Coord &coord );
public:
UISpot( const Spot &spot, QWidget *parent ) :
QPushButton( parent ),
spot_( spot ) {
connect( this, SIGNAL( clicked() ),
this, SLOT( buttonClicked() ) );
}
};
}
#endif // UISPOT_HPP
To copy to clipboard, switch view to plain text mode
And uiSpot.cpp:
#include "uiSpot.hpp"
namespace ttt {
void UISpot::buttonClicked() {
emit clickedAt( spot_.coord() );
}
}
#include "uiSpot.hpp"
namespace ttt {
void UISpot::buttonClicked() {
emit clickedAt( spot_.coord() );
}
}
To copy to clipboard, switch view to plain text mode
The Spot interface is irrelevent, so I didn't post it. Now, when I try to compile this, I get the following error messages:
$ qmake -project
$ qmake
$ make
...
<SNIP>
...
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o uiSpot.o uiSpot.cpp
uiSpot.hpp:15: error: expected primary-expression before ‘void’
uiSpot.hpp:15: error: ISO C++ forbids declaration of ‘type name’ with no type
uiSpot.hpp:15: error: expected ‘;’ before ‘void’
uiSpot.cpp:4: error: no ‘void ttt::UISpot::buttonClicked()’ member function declared in class ‘ttt::UISpot’
make: *** [uiSpot.o] Error 1
At line 15 is where I declare the slots and signals. What am I doing wrong?
Any help would be greatly appreciated.
Bookmarks