View Full Version : Linux QT4 app hangs on exit

18th June 2009, 17:01

I've been finishing off a port of a GIUI from QT3 to QT4, and have come across this problem on Linux.

The program starts up, loads a couple of dlls (Which widgets displayed in a QStrackedWidget, and when I exit, and clear everything up, the app hangs. It gets as far as the bottom of my main, where I have put :-

Printf("We have reached the end\n" );
return 0;

So I know it's right at the end. However something is hanging, since when I exit, we do not return to the prompt.

The same problem does not occur on Windows. I'm a bit stumped as to what may be causing this, and was wondering whether anyone had come across this.

I have printed the stack below. I'm currently using QT - 4.5.1, but the same problem occurred in an older version of QT4.

My Linux version is :-

Linux davidg-linux 2.6.24-24-generic #1 SMP Wed Apr 15 15:54:25 UTC 2009 i686 GNU/Linux

[Thread debugging using libthread_db enabled]
[New Thread 0xb6d138d0 (LWP 10793)]
[New Thread 0xb69bab90 (LWP 10796)]
We have reached the end << ---- I printed this out right at the end of my main(), before returning zero
[Thread 0xb69bab90 (LWP 10796) exited]

<< I then waited for a bit and did ctl-c, to break into the program, and print the stack >>

Program received signal SIGINT, Interrupt.
[Switching to Thread 0xb6d138d0 (LWP 10793)]
0xb7f8a410 in __kernel_vsyscall ()
(gdb) bt
#0 0xb7f8a410 in __kernel_vsyscall ()
#1 0xb7018553 in __lll_lock_wait_private ()
from /lib/tls/i686/cmov/libpthread.so.0
#2 0xb701596a in _L_lock_23 () from /lib/tls/i686/cmov/libpthread.so.0
#3 0xb7015718 in pthread_cond_destroy@@GLIBC_2.3.2 ()
from /lib/tls/i686/cmov/libpthread.so.0
#4 0xb713a818 in ~QMutexPrivate (this=0x8112048)
at /var/tmp/qt-x11-src-4.5.1/src/corelib/thread/qmutex_unix.cpp:70
#5 0xb7135be8 in ~QMutex (this=0xfffffe00)
at /var/tmp/qt-x11-src-4.5.1/src/corelib/thread/qmutex.cpp:134
#6 0x080695c0 in __tcf_0 ()
#7 0xb6dcf084 in exit () from /lib/tls/i686/cmov/libc.so.6
#8 0xb6db7458 in __libc_start_main () from /lib/tls/i686/cmov/libc.so.6
#9 0x08051bc1 in _start ()

19th June 2009, 02:43
can u print your main()?
may be u should not return 0, return app.exe()

int main(..)
QApplication app();
return app.exe();

19th June 2009, 10:07
I have stripped out some stuff that sets up logging etc in my main, and it basically looks like this :-

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

qApp->setStyle( new QCleanlooksStyle() );

app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));

MainDialog dialog( 0, Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint );

printf( "We have reached the end\n" );
return 0;

As I said previously, I load a number of shared objects (dll's in windows), which are the widgets I display in my widget stack.

On Linux, if I do not load the shared object, the app exits fine, but it seems the mere act of calling

NewPage.hinstLib = dlopen( Name.c_str(), RTLD_LAZY);

on one my shared objects, causes the app to get stuck.

BTW - This all works fine on windows, linux and solaris, with QT3.

19th June 2009, 10:22
did you tried returning app.exe() ?

edit:-> also use show() in maindialog instead of exec()

19th June 2009, 10:45
I changed the code as follows:

MainDialog dialog( 0, Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint );

return app.exec();

But I still get the hang on Linux. Looking at the output from GDB, it's still the same as in my initial post.

19th June 2009, 11:21
i bail out

28th August 2009, 17:01
I've resolved this issue in a strange way, but will investigate the cause later.

In my App I had the following :-

- Main app (exe).
- A number of widget which are built as shared object (.so/.dll).
- A static library which is linked into the main app and shared objects (.a/.lib).

On windows and solaris, everything is fine, but on linux, this method, causes the main app to hang on exit, when cleaning up and closing the shared objects.

I got around the problem by changing the structure to :-

- Main app (exe).
- A number of widget which are built as shared object (.so/.dll).

Now rather than having a static library linked in, which contains the shared code, which is duplciated in each shared object, I include the C++ files in each individual *.pro file for each shared object. Building like this stops the hang.

This is a very strange issue, but as I said, it resolves my issue for now, and enables me to conitnue with my dev on QT4.