[Qt-interest] Debugger for Qt threaded applications
Andreas Pakulat
apaku at gmx.de
Mon Oct 12 16:45:32 CEST 2009
On 12.10.09 09:45:07, Miguel Cardenas wrote:
> I need to debug a Linux Qt4 threaded application but have not a good tool.
> My current debugger is kdgb that works for simple programs. I have a
> threaded one that apparently works but randomly it causes segmentation fault
> when a button launches a thread, somtimes works, sometimes crashes and don't
> know where...
>
> Is there a good graphic debugger that I can use to findout where is the
> problem and be able to fix it?
Valgrind's helgrind tool should be able to point you to common
threading-problems in your app. However...
> Or perhaps you could give me an idea on what is going on... Normally the
> first time I start the thread it works, but after 2 or 3 times it crashes.
> Note that a single thread is launched, and the button that starts the thread
> is disabled while it is running, once it finishes the button is enabled to
> use it again.
>
> I have something like this: (pseudocode)
>
> ----------------------------------------------------------------
> class MyThread;
>
> class MyObject : QMainWindows {
> Q_OBJECT
> ...
> QPushButton myButton;
> MyThread *myThread; //
> public:
> MyObject();
> public slots:
> void startMyThread (void);
> }
>
> MyObject::MyObject {
> ...
> myThread = new MyThread();
> ...
> QObject::connect(myButton,SIGNAL(clicked()),this,SLOT(startMyThread));
> ...
> }
>
> void MyObject::startMyThread (void) {
> if ( myThread->isRunning() ) {
> QMessageBox::warning (0/*parent*/, tr("Warning"),
> tr("ALREADY RUNNING!"));
> return;
> } else {
> myThread->start();
> }
> }
This won't work AFAIK. You have to create a new thread-object each time you
want to start it. Restarting an already-finished QThread like this won't
work.
Andreas
--
You will have long and healthy life.
More information about the Qt-interest-old
mailing list