PDA

View Full Version : No such signal issue



mtrpoland
6th September 2007, 08:40
PROBLEM:

Object::connect: No such signal MTR::PawnBox::dragHasBegun(const MTR::PawnBox::Pawn*)

CODE:

#ifndef PAWNBOX_SAFETY_DECLARATION
#define PAWNBOX_SAFETY_DECLARATION
class QPaintEvent;
class QPixmap;
#include <QWidget>
#include <QRectF>
#include <QColor>
#include <QMap>

namespace MTRUTIL {
const int AMOUNT_OF_PAWNS = 8;
}

namespace MTR {
class PawnBox : public QWidget {
Q_OBJECT
public:
PawnBox(QWidget *parent = 0);
~PawnBox() { delete px; }
//klasa pionka
class Pawn {
public:
Pawn();
Pawn(QColor &color, QRectF &rec, QString &id);
~Pawn();
const QColor &color() const { return color_; }
const QRectF &rectF() const { return rectF_; }
const QString &id() const { return id_; }
const QPixmap &internalPicture() const { return dragPicture; }
private:
void paintInternalPicture();
QColor color_;
QRectF rectF_;
QString id_;
QPixmap dragPicture;
};
//
signals:
void dragHasBegun(const Pawn *pw);
protected:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
private:
void startDrag();
QPoint startPos;
QPixmap *px;
bool insidePawn;
Pawn *draggedPawn;
QMap<int, Pawn> pawnCollection;
};
}
#endif



void PawnBox::startDrag() {
QMimeData *mimeData = new QMimeData;
mimeData->setText(draggedPawn->id());
QDrag *drag = new QDrag(this);
drag->setPixmap(draggedPawn->internalPicture());
drag->setMimeData(mimeData);
drag->setHotSpot(QPoint(10,10));

drag->setDragCursor(*px,Qt::MoveAction);
drag->setDragCursor(*px,Qt::CopyAction);
const Pawn *pt = draggedPawn;
emit dragHasBegun(pt);
drag->start(Qt::MoveAction);

}


#ifndef GAMEWIDGET_SAFETY_DECLARATION
#define GAMEWIDGET_SAFETY_DECLARATION
class QPaintEvent;
class QMouseEvent;
class QDragMoveEvent;
class QDragEnterEvent;
#include "../MTRPawnBox/mtrpawn.hpp"
#include <QWidget>

namespace MTR {
class GameWidget : public QWidget {
Q_OBJECT
public:
GameWidget(QWidget *parent = 0);
public slots:
void setDraggedPawnPointer(const PawnBox::Pawn *pw);
//void debugOne() { qDebug(draggedPawn->id().toStdString().c_str()); }
protected:
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
private:
MTR::PawnBox::Pawn *draggedPawn;
};
}
#endif



void GameWidget::setDraggedPawnPointer(const PawnBox::Pawn *pw) {
if(pw) draggedPawn = const_cast<PawnBox::Pawn *>(pw);
else draggedPawn = 0;
}

All is connected in main window widget:

connect(pawnBox,SIGNAL(dragHasBegun(const MTR::PawnBox::Pawn *)),gameScreen,SLOT(setDraggedPawnPointer(const MTR::PawnBox::Pawn *)));
where

MTR::PawnBox *pawnBox;
QWidget *firstMenuScreen;
QWidget *rulesScreen;
QWidget *resultsScreen;
QWidget *gameChoiceScreen;
QWidget *globalRecordsScreen;
QWidget *localRecordsScreen;
MTR::GameWidget *gameScreen;

marcel
6th September 2007, 08:48
I think you have to declare the signal as:


void dragHasBegun(const MTR::PawnBox::Pawn*);


Moc takes things "literally".

Regards

mtrpoland
6th September 2007, 09:25
It worked.
I wouldn't come up with such idea nor would I seek solution in this directory.
I could have only groped for some solution.
Thanks

marcel
6th September 2007, 09:41
OK. But I think you also have to use qRegisterMetatype in order to be able to pass custom types between signals and slots.

Regards

Gopala Krishna
6th September 2007, 11:14
OK. But I think you also have to use qRegisterMetatype in order to be able to pass custom types between signals and slots.

Regards

Hmm.. you are partly right marcel.
qRegisterMetaType doc says that the registering is need only for queued connections.
I tried some of my own examples and from that i can conclude

If the parameter is pointer type no registering is needed for all connection type.
If the parameter is non pointer custom class type then registering is needed only
when using queued connection.
EDIT: The default connection is not queued.

marcel
6th September 2007, 11:23
Well, I said "I think". :)

Gopala Krishna
6th September 2007, 11:27
Well, I said "I think". :)

You are right, but thanks actually for letting me know this. This is the first time i am encountering qRegisterMetaType's relation to signal/slots.
Thanks for making me 'think' :)

marcel
6th September 2007, 11:39
You are right, but thanks actually for letting me know this. This is the first time i am encountering qRegisterMetaType's relation to signal/slots.
Thanks for making me 'think' :)

OK, but I am not sure you are right, though... :)
I never used qRegisterMetaType myself, but I was pretty sure that you have to register a custom type in order to use it with signals/slots.

I'll make a test as soon as I get off work.

Regards

Gopala Krishna
7th September 2007, 09:05
OK, but I am not sure you are right, though... :)
I never used qRegisterMetaType myself, but I was pretty sure that you have to register a custom type in order to use it with signals/slots.

I'll make a test as soon as I get off work.

Regards

Did you test ?

wysota
7th September 2007, 10:09
When the type is not registered, you'll get a runtime warning about not being able to "queue arguments of type XXX" or something like that. I wouldn't rely on assuming the connection type - if you want to use a type in signal/slots connections (types, not pointers to them), it's better to register it. Note that it's also possible to declare a metatype for a type.