slots and signals don't seem to be recognized
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:
Code:
#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
And uiSpot.cpp:
Code:
#include "uiSpot.hpp"
namespace ttt {
void UISpot::buttonClicked() {
emit clickedAt( spot_.coord() );
}
}
The Spot interface is irrelevent, so I didn't post it. Now, when I try to compile this, I get the following error messages:
Quote:
$ 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. :)
Re: slots and signals don't seem to be recognized
I've never seen 'slots:' in a class without a visibility specification. It might not be the error, but it is worth a try. In your case, I guess that would be 'private slots:'.
Also, you might be interested in auto-connect slots. It's a Qt slot naming convention (on_<object>_<signal>). If you call your slot 'on_this_clicked()', you don't need to explicitly connect.
Re: slots and signals don't seem to be recognized
Quote:
Originally Posted by
Michiel
I've never seen 'slots:' in a class without a visibility specification. It might not be the error, but it is worth a try. In your case, I guess that would be 'private slots:'.
Also, you might be interested in auto-connect slots. It's a Qt slot naming convention (on_<object>_<signal>). If you call your slot 'on_this_clicked()', you don't need to explicitly connect.
Thanks Michiel. The private slots did it. :)