Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Unhandled - Thread
Forum Updated to NodeBB v4.3 + New Features

Unhandled - Thread

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    romeo.rbw
    wrote on last edited by
    #1

    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;

    cObject.DoSetup(cThread);
    cObject.moveToThread(&cThread);
    
    if (X3 >=415 && X3<=470 && Y3 >=225 && Y3<=238){  //my condition to enter thread
        cThread.start();
    
        qDebug() << "finish" ;
    
    }
    

    @

    in myobject.h
    @
    #ifndef MYOBJECT_H
    #define MYOBJECT_H

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

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

    signals:

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

    in myobject.cpp
    @
    #include "myobject.h"

    MyObject::MyObject(QObject *parent) :
    QObject(parent)
    {
    }

    void MyObject::DoSetup(QThread &cThread)
    {
    connect(&cThread,SIGNAL(started()),
    this,SLOT(DoWork()));
    }

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

    @

    Thanks in advance.

    -romeo

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        romeo.rbw
        wrote on last edited by
        #3

        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.
        -romeo

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

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

          For MSVC you should have CDB installed. See "QtCreator: Setting Up Debugger":http://doc.qt.nokia.com/qtcreator-2.5/creator-debugger-engines.html.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            romeo.rbw
            wrote on last edited by
            #5

            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.
            -romeo

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved