Hi everyone,
I have a problem connecting a signal to a slot.
I'm making a chessgame using QGraphicsView and an array of DnDPixmaps:
#ifndef DNDPIXMAP_H
#define DNDPIXMAP_H
#include <QPixmap>
#include <QObject>
#include <QGraphicsPixmapItem>
#include <QGraphicsSceneDragDropEvent>
class uitzicht;
{
Q_OBJECT
// No Q_OBJECT macro, as QGraphicsPixmapItem is not derived from QObject!
public:
// Constructor gets a QPixmap which it will display.
DnDPixmap
(const QPixmap &pixmap, uitzicht
* a
);
int oudeX;
int oudeY;
protected:
// Overloaded methods to enable dragging.
// Overloaded methods for dropping.
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
signals:
void moveMade( int x, int y, int oudeX, int oudeY);
private:
// This member holds the copied QPixmap resulting from a drop.
};
#endif // DNDPIXMAP_H
#ifndef DNDPIXMAP_H
#define DNDPIXMAP_H
#include <QPixmap>
#include <QObject>
#include <QGraphicsPixmapItem>
#include <QGraphicsSceneDragDropEvent>
class uitzicht;
class DnDPixmap:public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
// No Q_OBJECT macro, as QGraphicsPixmapItem is not derived from QObject!
public:
// Constructor gets a QPixmap which it will display.
DnDPixmap(const QPixmap &pixmap, uitzicht* a);
int oudeX;
int oudeY;
protected:
// Overloaded methods to enable dragging.
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
// Overloaded methods for dropping.
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
virtual void dropEvent(QGraphicsSceneDragDropEvent *event);
signals:
void moveMade( int x, int y, int oudeX, int oudeY);
private:
// This member holds the copied QPixmap resulting from a drop.
QPixmap pix;
};
#endif // DNDPIXMAP_H
To copy to clipboard, switch view to plain text mode
#include "dndpixmap.h"
#include <QMimeData>
#include <QList>
#include <QUrl>
#include <QMessageBox>
#include <QDrag>
#include <QApplication>
#include "uitzicht.h"
DnDPixmap
::DnDPixmap(const QPixmap &pixmap, uitzicht
* a
){
// Make sure we allow drops.
setAcceptDrops(true);
connect(this, SIGNAL(moveMade( int, int, int, int)), a, SLOT(myslot( int, int, int, int)));
}
//more stuffs
#include "dndpixmap.h"
#include <QMimeData>
#include <QList>
#include <QUrl>
#include <QMessageBox>
#include <QDrag>
#include <QApplication>
#include "uitzicht.h"
DnDPixmap::DnDPixmap(const QPixmap &pixmap, uitzicht* a)
: QGraphicsPixmapItem(pixmap)
{
// Make sure we allow drops.
setAcceptDrops(true);
connect(this, SIGNAL(moveMade( int, int, int, int)), a, SLOT(myslot( int, int, int, int)));
}
//more stuffs
To copy to clipboard, switch view to plain text mode
my view:
#include "uitzicht.h"
#include "Spelbord.h"
#include <QGraphicsView>
#include <QGraphicsScene>
#include "dndpixmap.h"
void uitzicht::myslot(const int x, const int y, const int oudeX, const int oudeY){
//see if the move is possible
//Schaakstuk* a = bord->geefSchaakStuk(oudeX, oudeY);
//if yes update the model by changing the table
bord->verplaatsSchaakStuk(oudeX, oudeY, x, y);
//update the view, if needed
this->print();
}
#include "uitzicht.h"
#include "Spelbord.h"
#include <QGraphicsView>
#include <QGraphicsScene>
#include "dndpixmap.h"
void uitzicht::myslot(const int x, const int y, const int oudeX, const int oudeY){
//see if the move is possible
//Schaakstuk* a = bord->geefSchaakStuk(oudeX, oudeY);
//if yes update the model by changing the table
bord->verplaatsSchaakStuk(oudeX, oudeY, x, y);
//update the view, if needed
this->print();
}
To copy to clipboard, switch view to plain text mode
#ifndef UITZICHT_H
#define UITZICHT_H
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QPixmap>
#include <QGraphicsItem>
#include <QPen>
#include <QBrush>
#include <QGraphicsScene>
#include "Spelbord.h"
#include "dndpixmap.h"
class uitzicht
{
public:
void print();
public slots:
void myslot( int x, int y, int oudeX, int oudeY);
private:
DnDPixmap*bordview [Spelbord::MAX][Spelbord::MAX];
Spelbord* bord;
bool witAanZet;
};
#endif // UITZICHT_H
#ifndef UITZICHT_H
#define UITZICHT_H
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QPixmap>
#include <QGraphicsItem>
#include <QPen>
#include <QBrush>
#include <QGraphicsScene>
#include "Spelbord.h"
#include "dndpixmap.h"
class uitzicht
{
public:
uitzicht(Spelbord* model, QGraphicsScene* scene);
void print();
public slots:
void myslot( int x, int y, int oudeX, int oudeY);
private:
DnDPixmap*bordview [Spelbord::MAX][Spelbord::MAX];
Spelbord* bord;
bool witAanZet;
QGraphicsScene* scene;
};
#endif // UITZICHT_H
To copy to clipboard, switch view to plain text mode
In the constructor of DnDPixmap, I want to connect the signal 'moveMade' to the slot of the view 'mySlot', but I get this error:
dndpixmap.cpp:17: error: no matching function for call to 'DnDPixmap::connect(DnDPixmap* const, const char*, uitzicht*&, const char*)'
I already derived DnDPixmap from QObject as I learned from another thread outhere, though it's still not working
Can someone help me with this please?
Thanks in advance!
Bennieboj
Bookmarks