Results 1 to 9 of 9

Thread: QThread crashes on exit

  1. #1
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QThread crashes on exit

    QThread attempts to lock something when it exits using a QMutexLocker class.

    Qt Code:
    1. void QThread::exit(int returnCode)
    2. {
    3. Q_D(QThread);
    4. QMutexLocker locker(&d->mutex); // <------ Crashes here! d == 0x0
    5. d->data->quitNow = true;
    6. for (int i = 0; i < d->data->eventLoops.size(); ++i) {
    7. QEventLoop *eventLoop = d->data->eventLoops.at(i);
    8. eventLoop->exit(returnCode);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Just trying to declare the QMutexLocker causes a crash.

    This looks like a Qt bug, but I'm not sure.

    Any ideas? It looks like "d" might not have been allocated.

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QThread crashes on exit

    now see... thousands of ppl use QThread everyday.. if it was so easy to crash it than it would have been found and fixed there and then... so the problem is in your case..
    whenever your proggi crashes in Qt code, then make a minimal compilable example that would reproduce the bug and submit it to trolltech... it would also be helpful to answer you if you submit it here ...

  3. The following user says thank you to nish for this useful post:

    mhoover (25th August 2009)

  4. #3
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QThread crashes on exit

    Is there core dump?
    I'm a rebel in the S.D.G.

  5. The following user says thank you to lyuts for this useful post:

    mhoover (25th August 2009)

  6. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QThread crashes on exit

    Aren't you calling exit() on an uninitialized QThread pointer by any chance?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    mhoover (25th August 2009)

  8. #5
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QThread crashes on exit

    There is no core dump. How do you enable that again? I'm using RedHat if that matters.

    In this case the threads are declared as member variables on the stack, so the threads can't be uninitialized pointers. I suppose there could be other uninitialized pointers ...

    I realize there are a lot of people who use QThreads all the time, but I don't think a large portion of the herd is running in my direction (lots of threads containing networking classes). The other thing is I wonder how a private Qt-class variable is not initialized ...

  9. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QThread crashes on exit

    Quote Originally Posted by mhoover View Post
    In this case the threads are declared as member variables on the stack, so the threads can't be uninitialized pointers.
    Sure they can.

    The other thing is I wonder how a private Qt-class variable is not initialized ...
    Probably because it was deleted or has not been initialized yet. Or... you have stack corruption.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    mhoover (25th August 2009)

  11. #7
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QThread crashes on exit

    Thanks again, everyone for your help.

    This solved the problem:

    Qt Code:
    1. UDPThread::~UDPThread()
    2. {
    3. exit();
    4. while( this->isRunning() == true ) {
    5.  
    6. }
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    My assumption was exit() didn't return until the thread was finished running, but it keeps going.

    It looks like exit() stops the event loop and then stops the run() a bit later.
    Last edited by mhoover; 25th August 2009 at 22:34.

  12. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QThread crashes on exit

    try to use "native" methods of QThread
    Qt Code:
    1. UDPThread::~UDPThread()
    2. {
    3. if (isRunning()) {
    4. quit();
    5. wait();
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  13. #9
    Join Date
    Jan 2006
    Location
    Maui, Hawaii
    Posts
    120
    Thanks
    65
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QThread crashes on exit

    Oh, right.

    I was trying to use the intellisense thing to quickly see what methods were available.

    I will change it.

Similar Threads

  1. QThread and QTcpSocket
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 12th May 2008, 13:06
  2. QThread exec proplem to stop...
    By patrik08 in forum Qt Programming
    Replies: 29
    Last Post: 21st May 2007, 07:51
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  4. QThread stack overflow when exiting
    By jakamph in forum Qt Programming
    Replies: 4
    Last Post: 11th May 2006, 17:56
  5. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 22:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.