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. Error using QApplication::notify
Forum Update on Monday, May 27th 2025

Error using QApplication::notify

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.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.
  • D Offline
    D Offline
    Dcqt
    wrote on 4 Mar 2014, 08:46 last edited by
    #1

    test.h

    @class TestApp : public QWidget, public QApplication
    {
    public:
    TestApp(QWidget *parent = 0);
    bool notify(QObject *receiver, QEvent *event);
    };@

    test.cpp

    @bool TestApp:: notify(QObject *receiver, QEvent *event)
    {
    try
    {

        if(event->type() == QEvent::KeyPress)
        {
         QKeyEvent *ke = (QKeyEvent *) event;
         int keyValue = ke->key();
         qDebug() << "Key Value is" << keyValue;
        }
      return QApplication::notify(receiver, event);
     }
     catch(std::exception& e)
     {
      qDebug() << "Exception thrown:" << e.what();
     }
    

    }@

    main.cpp
    @
    int main(int argc, char *argv[])
    {
    QApplication testQapp(argc, argv);

    TestApp objTestApp;
    objTestApp.show();
    
    return testQapp.exec();
    

    }@

    I am trying to use function notify to receive the key events , but i am getting error

    error: cannot call member function 'virtual bool QApplication::notify(QObject*, QEvent*)' without object

    if i use
    class TestApp : public QWidget

    and getting
    error: no matching function for call to 'QApplication::QApplication()'

    if i use
    class TestApp : public QWidget, public QApplication.

    please suggest me how to call correct way.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on 4 Mar 2014, 12:44 last edited by
      #2

      You cannot derive a class from QObject twice. Both QApplication and QWidget derive from QObject.

      Do you want to receive the key events within the widget? Use QWidget's key events like keyPressEvent.
      Do you want to receive the key events for the whole applications? Take a look at QCoreApplication::setEventFilter

      1 Reply Last reply
      0

      1/2

      4 Mar 2014, 08:46

      • Login

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