PDA

View Full Version : Surprising problem when making a subclass of a subclass of QApplication



latinum
10th April 2013, 14:08
Hello,

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
{
public:
A_App(int argc, char** argv) : QApplication(argc, argv)
{
}
};

#if MAKE_IT_DIE
typedef A_App SUPER;
#else
typedef QApplication SUPER;
#endif

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

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

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

return app.exec();
}

fullmetalcoder
15th April 2013, 04:02
For what it's worth, the QApplication constructor (http://qt-project.org/doc/qt-4.8/qapplication.html#QApplication) 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 (https://bugreports.qt-project.org/secure/Dashboard.jspa).

latinum
15th April 2013, 07:33
'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 !

RTFMC(arefully).

Regards and thanks again,
John