How to catch MouseEvent from QGraphicsScene, LinkError



  • Hi

    im trying to catch mouseevents from QGraphicsScene by using this ugly SIGNAL-SLOT mechanism.

    Im getting compile error: "error LNK2019" mouseClick not found...

    I hope some one can tell me what im doing wrong.

    thx

    cgraphicsscenePlugins.h
    @
    #ifndef CGRAPHICSSCENEPLUGINS_H
    #define CGRAPHICSSCENEPLUGINS_H

    #include <QGraphicsScene>
    #include <QGraphicsSceneMouseEvent>
    #include <QObject>

    class CGraphicsScenePlugins : public QGraphicsScene{

    public:
    CGraphicsScenePlugins(QObject *parent = 0);

    protected:
    void mousePressEvent(QGraphicsSceneMouseEvent* event );

    signals:
    void mouseClick(QGraphicsSceneMouseEvent* event);
    };

    #endif // CGRAPHICSSCENE_H
    @

    cgraphicsscenePlugins.cpp

    @
    #include "cgraphicsscenePlugins.h"

    CGraphicsScenePlugins::CGraphicsScenePlugins(QObject *parent) : QGraphicsScene() {
    }

    void CGraphicsScenePlugins::mousePressEvent(QGraphicsSceneMouseEvent * event ) {
    QGraphicsScene::mousePressEvent(event);
    emit mouseClick(event);
    }

    @



  • If you would like to emit signals, then your class should be marked as Q_OBJECT

    @
    class CGraphicsScenePlugins : public QGraphicsScene{
    Q_OBJECT
    @

    then do not forget to call qmake and to add header to .pro file

    @
    HEADERS += cgraphicsscenePlugins.h
    @



  • I think that signals and slots are not required in your case. You can call a simple method instead of emitting a signal or you can write the code that you want the application to execute when it receives a mouse press event, inside the mousePressEvent() method. it will be executed automatically !!



  • Even i got the same error.. Please help me..!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.