Results 1 to 3 of 3

Thread: Surprising problem when making a subclass of a subclass of QApplication

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2013
    Qt products

    Post Surprising problem when making a subclass of a subclass of QApplication


    I am trying to subclass QApplication into two levels but I have discovered some amazing behaviour. My OS is Centos 6.3 and I am using qt4.7 as made available via the atrpms repo mentioned on the Centos website. The entire test jig, a suitable makefile and the gdb backtrace of the failure can be seen in the attached test.cpp file.

    My test application itself (also shown below) draws a single button in a window. The button has a tooltip.

    When my QApplication derived class is an immediate subclass of QApplication, the application works as expected. When I hover over the button and wait a bit, I see my tool tip.

    However, if my test app is a subclass of a subclass of QApplication, the story is very different. The application starts fine but when I hover over the button and wait the popup delay time, the popup does not appear and the app dies somewhere in code relating to X (XSetCommand) !

    Interestingly, this behaviour is not observed on Centos 5. In fact it also doesn't happen when I run my Centos 6-compiled test binary on Centos 5 'as is'.

    I am completely stumped by what could cause this weird behaviour but its pretty easy to prove. Can anybody give me any insight into what might be the cause ??

    Thanks in advance.

    #include <QtGui/qtoolbutton.h>
    #include <QtGui/qapplication.h>
    #define MAKE_IT_DIE 1

    class A_App : public QApplication
    A_App(int argc, char** argv) : QApplication(argc, argv)

    #if MAKE_IT_DIE
    typedef A_App SUPER;
    typedef QApplication SUPER;

    class B_App : public SUPER
    B_App(int argc, char** argv) : SUPER(argc, argv)

    main(int argc, char** argv)
    B_App app(argc, argv);

    QToolButton* f = new QToolButton;
    f->setToolTip("HELLO WORLD");

    return app.exec();
    Attached Files Attached Files
    Last edited by latinum; 10th April 2013 at 13:12. Reason: spelling corrections

  2. #2
    Join Date
    Jan 2006
    Thanked 127 Times in 121 Posts
    Qt products
    Unix/X11 Windows

    Default Re: Surprising problem when making a subclass of a subclass of QApplication

    For what it's worth, the QApplication constructor takes a reference to an int so depending on how that variable ends up being used (e.g. if the reference is converted into a pointer and passed to some subsystem that tries to access it outside of the stack frame where it is valid) it could be an issue. Try replacing "int argc" with "int& argc" in A_App and B_App constructors. If it doesn't help you should report the bug.
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Apr 2013
    Qt products

    Thumbs up Re: Surprising problem when making a subclass of a subclass of QApplication

    'For what its worth' you say.. ! Its worth heaps !! ALL my wierdness has disappeared. Thankyou so, so much.

    The example program I provided was taken from a much larger project that has been working for YEARS and yet only recently did this error reveal itself in dozens of mysterious ways - the tooltip being the easiest to replicate.

    All my modes of failure inevitably crashed somewhere in X (typially XSetCommand but elsewhere in X too) which I've just realised recently are passed argc and argv. When I read your mention or argc, I just knew it was likely to work !


    Regards and thanks again,

Similar Threads

  1. Replies: 4
    Last Post: 14th September 2012, 17:13
  2. KDChart: add horizontal lines (levels/markers)
    By galrub in forum KDE Forum
    Replies: 0
    Last Post: 5th August 2012, 18:02
  3. type casting 5 levels down no error but not proper
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 4
    Last Post: 29th April 2012, 14:04
  4. Nested tables (different columns at sub levels)
    By lfiedler in forum Qt Programming
    Replies: 0
    Last Post: 18th March 2011, 16:26
  5. Subclass Problem
    By rleojoseph in forum Newbie
    Replies: 21
    Last Post: 4th February 2011, 06:43

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.