xx77aBs
xx77aBs

Reputation: 4768

How to debug Qt command line application ? Help!

I'm having some rather strange problems with my Qt application...

Application is written to work in terminal/command prompt, and it consists of two threads (+ main one that only starts other two and executes event loop). These two threads don't share any resources (they both have their own version of QNetworkAccessManager, QSqlDatabase and so on ...), so I don't use QMutex or any other similar mechanism. The problem is that sometimes my application just crashes few seconds after I start it. I don't know what is the problem, and I can't get useful answer with QtCreator's built-in debugger (or I don't know how to do it). The funny thing is that these errors (that crashes my app) are occurring randomly (at least I can't find a pattern), and when I don't start one of the two threads, everything is working fine. But again, they do not use any common resources ...

Here are few screenshots, I don't understand why there are only Qt framework functions in stack trace (not one function that I have written - like the error happens before my code executes, but that's not true)...

This is the one I get most frequently:

http://img859.imageshack.us/f/75996377.png/

And these two I get just sometime:

http://img690.imageshack.us/f/23373599.png/

http://img687.imageshack.us/f/25248518.png/

Upvotes: 0

Views: 697

Answers (1)

Judge Maygarden
Judge Maygarden

Reputation: 27563

You only see Qt code in the stack trace because the errors are occurring in the event loop (i.e. QCoreApplication::exec). I see Win32 calls related to thread local storage in your stack traces. Are you creating the QNetworkAccessManager, QSqlDatabase, etc. instances within the context of each thread that uses them or in the main thread before the others are started? Qt does some work behind the scenes that requires these to be instantiated in the context of the thread that has ownership. If global data is in thread local storage and the thread trying to access the data does not have scope to it, then you'll have problems!

Otherwise, using a debugger to find race conditions is extremely difficult. That's part what makes multi-threaded programming so hard to get right. I would advise researching how those Qt objects behave when used from multiple threads. Examine your architecture instead of trying to find an answer with the debugger.

Upvotes: 1

Related Questions