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. [SOLVED] Simplest QApplication inheritance: segmentation fault on Linux only
QtWS25 Last Chance

[SOLVED] Simplest QApplication inheritance: segmentation fault on Linux only

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.8k 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.
  • F Offline
    F Offline
    floatingWoods
    wrote on 24 Oct 2013, 13:57 last edited by
    #1

    Hello,

    I came across a strange behaviour. I inherit from QApplication in order to be able to intercept an application-wide esc-key.
    Here I create the QApplication:

    @myQApplicationClass* myApp=new myQApplicationClass(qApp_argc,qApp_argv);@

    and this is my 'myQApplicationClass':

    @myQApplicationClass::myQApplicationClass(int argc ,char** argv) : QApplication(argc,argv)
    {
    }

    myQApplicationClass::~myQApplicationClass()
    {
    }

    bool myQApplicationClass::notify(QObject* object,QEvent* event)
    {
    if(event->type()==QEvent::KeyPress)
    {
    QKeyEvent* keyEvent=static_cast<QKeyEvent*>(event);
    int key=keyEvent->key();
    if (key==Qt::Key_Escape)
    // do something
    }
    return(QApplication::notify(object,event));
    };
    @

    The first time I call a 'show' (e.g. on the splash screen or any other) the application crashes, but only on Linux (32 and 64bits). Windows works fine. When removing the 'notify' function, I get the same result. Only if I use myApp like follows, will it not crash on Linux:

    @QApplication* myApp=new QApplication(qApp_argc,qApp_argv); // i.e. regular way to call it@

    (with above line, the problems on Linux are resolved, but I don't have a global key press handler anymore).
    Am I doing something wrong? Missing something? Or did I discover a bug?

    Thanks

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 24 Oct 2013, 14:07 last edited by
      #2

      constructor signature is wrong, it should be:
      @
      myQApplicationClass(int & argc ,char** argv)
      @
      (pass argc as a reference instead of a copy)

      And btw. you can simply avoid subclassing QApplication at all and install an eventFilter on it and filter for the Esc-KeyEvent.
      @
      qApp->installEventFilter(object);
      @
      The event filter is called right after QApplication::notify() but still before any event gets delivered to a widget.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • F Offline
        F Offline
        floatingWoods
        wrote on 24 Oct 2013, 16:07 last edited by
        #3

        A big big thank you Raven-worx! It's the '&' that I forgot that was the culprit!

        1 Reply Last reply
        0

        1/3

        24 Oct 2013, 13:57

        • Login

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