Important: Please read the Qt Code of Conduct -

Unhandled - Thread

  • Hello Qt-ers,

    I tried using a Thread. The function in Thread already loaded successfully by the program, but there is a dialog box appeared if the condition to enter the thread provided by user, it could many times display (2 times if thread twice called, or 10 times is thread 10 times called, etc). The dialog Box is a Visual Studio Just-In-Time Debugger, the message is "An unhandled Win32 exception occured in mythread.exe [6536]".
    But the application still running. Would you help me to explain or give me some suggestion? Here is my method of thread, I follow from one of the youtube Qt video tutorial but modified and implemented it for my application. Sorry about my English.

    in mainwindow.cpp
    QThread cThread;
    MyObject cObject;

    if (X3 >=415 && X3<=470 && Y3 >=225 && Y3<=238){  //my condition to enter thread
        qDebug() << "finish" ;


    in myobject.h
    #ifndef MYOBJECT_H
    #define MYOBJECT_H

    #include <QObject>
    #include <QThread>
    #include <QDebug>

    class MyObject : public QObject
    explicit MyObject(QObject *parent = 0);
    void DoSetup(QThread &cThread);


    public slots:
    void DoWork();
    #endif // MYOBJECT_H

    in myobject.cpp
    #include "myobject.h"

    MyObject::MyObject(QObject *parent) :

    void MyObject::DoSetup(QThread &cThread)

    void MyObject::DoWork()
    for(int i=0 ; i<20 ; i++){
    qDebug() << i;


    Thanks in advance.


  • Your <code>cThread</code> object is most probably going out of scope before the thread has finished its operation (and thus the thread is destroyed while it is still running).

    Apart from that your example should work as expected.

    Have you tried running your application in debug mode to see where it actually crashes?

  • Thanks for the reply..
    You are right there is a message about Thread was destroyed in my application output. How to fix that and what does it mean?

    I used "Qt 4.8.0 for Desktop-MSVC2010(Qt SDK) Release" before. The application running. But I try to change to "Qt 4.8.0 for Desktop-MSVC2010(Qt SDK) Debug" mode, but after I hit Ctrl-R there was a dialog box Microsoft Visual C++ Runtime Library, the message is Program:.._MSVC2010__Qt_SDK_Debug\debug\mythread.exe abnormal program termination.

    When I hit Start Debug in the toolbar, there was two Qt Warning dialog boxes. The messages are:

    • Message in the second dialog box. This does not seem to be a "Debug" build. Setting breakpoints by file name and line number may fail.

    • Message in the first dialog box. The preferred debugger engine for debugging binaries of type 'x86-windows-msvc2010-pe-32bit' is not available. The debugger engine 'Gdb engine' will be used as a fallback. Details: There is no CDB library availble for binaries in format 'x86-windows-msvc2010-pe-32bit'

    Do you have any suggestion to fix that so I cannot debug now.
    Thank you in advance.

  • Did you rebuild your application after switching from release to debug?

    For MSVC you should have CDB installed. See "QtCreator: Setting Up Debugger":

  • Yes, I rebuild the application.
    It is difficult to find CDB instalation for MSVC, I only found something like WSK-SDK from Microsoft web and could not install in my XP windows.
    Is there a suggestion to handle a message about 'Thread was destroyed while it is running' in my application output? I think if I can handle it may be the problem solved.
    Thank in advance.

  • Yes, create your thread object at a larger scope, for example as a member of your class or on the heap, so it won't go out of scope (and thus beeing destroyed) before your thread has finished execution.

Log in to reply