Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to catch MouseEvent from QGraphicsScene, LinkError

How to catch MouseEvent from QGraphicsScene, LinkError

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _dit
    wrote on last edited by
    #1

    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);
    }

    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      guziemic
      wrote on last edited by
      #2

      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
      @

      1 Reply Last reply
      0
      • I Offline
        I Offline
        issam
        wrote on last edited by
        #3

        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 !!

        http://www.iissam.com/

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Macro
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved