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 get data out of reimplemented QApplication notify
QtWS25 Last Chance

How to get data out of reimplemented QApplication notify

Scheduled Pinned Locked Moved General and Desktop
qapplnotify
4 Posts 3 Posters 1.9k 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.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by McLion
    #1

    Hi

    I have reimplemented QApplicaction notify.
    Everything works perfect. I now need to catch the mouse cursor position and the click events and have them in my main class. How do I get them out of the notifier of MyApplication to my QTGUI_MainWindow class and use them there in the function ?
    Calling TouchEvent as below does not work. I also tried to create a new QTGUI_MainWindow object and use this ... copiles but crashes .

    class MyApplication : public QApplication
    {
      public:
        MyApplication(int &argc, char **argv ) : QApplication(argc, argv)
        {
        }
    
        virtual bool notify ( QObject *receiver, QEvent *event )
        {
          switch( event->type() )
          {
            case QEvent::MouseButtonPress:
            case QEvent::MouseButtonRelease:
            case QEvent::MouseMove:
            case QEvent::MouseButtonDblClick:
            {
              if(bTouchActive)
              { QMouseEvent *TEvent = static_cast<QMouseEvent *>(event);
                QPoint cursorPos = TEvent->globalPos();
                TouchEvent(event->type(), cursorPos.rx(), cursorPos.ry());
                qDebug("Touch/Mouse event type: %d at %d, %d", event->type(), cursorPos.rx(), cursorPos.ry());
              }
              else
              { QMouseEvent *TEvent = static_cast<QMouseEvent *>(event);
                QPoint cursorPos = TEvent->globalPos();
                //qDebug("TouchInActive at %d, %d", cursorPos.rx(), cursorPos.ry());
                return true;  // return with true filters the event
              }
              break;
            }
            case QEvent::KeyPress:
            case QEvent::KeyRelease:
            { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
              qDebug("Key %d pressed, Event type: %d", keyEvent->key(), event->type());
              break; // break does not filter and forwards the event to QApplication::notify()
            }
            default:
              break;
          }
          QApplication::notify(receiver,event);
          return false;
        }
    };
    

    I know, it's about basic c++ understanding (classes ... ).
    However, I tried everything and don't seem to able to get it.
    Any hints are highly appreciated.
    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why don't you just reimplement the related event handler in your main window ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      McLionM 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Why don't you just reimplement the related event handler in your main window ?

        McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #3

        @SGaist

        I did that first, but I had some performance issues and this could be solved this way.

        I'll try the following (which works for a plain signal w/o parameters .. and should work with parameters as well). I am not sure if this is "best practice", but it works:

        • Add a signal to the reimplemented QApplication MyApplication class
        • In main: connect the signal to a slot of my MainWindow class
        1 Reply Last reply
        0
        • T3STYT Offline
          T3STYT Offline
          T3STY
          wrote on last edited by T3STY
          #4

          After I saw that bTouchActive variable there I would say you're trying to manage a touch surface. In this case, why don't you have a look at QGesture ? It might be better suited for the task instead of tracking the mouse position in real time. By the way, real time mouse tracking is very intensive and it might be the reason why your event handler reimplementation is creating performance issues.

          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