Results 1 to 3 of 3

Thread: QProgressDialog causing crash when used inside of a QThread class

  1. #1
    Join Date
    May 2010
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QProgressDialog causing crash when used inside of a QThread class

    All,

    I have a class that inherits from QThread. In the run() method I have a for loop that performs my calculations. Because this takes several minutes I would like to use QProgressDialog. I am using it as follows

    Qt Code:
    1. QProgressDialog progress(tr("Training the system..."),tr("Cancel"),0, numPts,0);
    2. progress.setCancelButton(0);
    3. progress.setWindowModality(Qt::WindowModal);
    4.  
    5. for(int ii = 0; ii < numPts; ii++)
    6. {
    7. progress.setValue(ii);
    8. ...
    9. }
    10. progress.setValue(numPts);
    11. progress.close();
    To copy to clipboard, switch view to plain text mode 

    When I run my code I get the following errors:
    ASSERT failure in QWidget: "Widgets must be created in the GUI thread.", file kernel\qwidget.cpp, line 1231
    ASSERT: "qApp && qApp->thread() == QThread::currentThread()" in file kernel\qapplication_win.cpp, line 929
    If I comment out all the lines using progress the code runs fine.

    The weird thing is that this is seemingly a function of numPts. When I use a dataset where I need to loop 54877 times (numPts) progress works. When I use a dataset where I need to loop 99116 times (numPts) progress causes the crash above.

    I don't even know where to start on debugging this so any help is gratefully appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QProgressDialog causing crash when used inside of a QThread class

    You cant use gui classes in a thread! All QWidgets have to stay in the main thread. Therefore create the progress dialog there and update it through signal and slots with the worker thread.

  3. #3
    Join Date
    May 2010
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QProgressDialog causing crash when used inside of a QThread class

    Thanks, I'll do that.

    I figured that was the case by what the error messages state, but it doesn't make sense on why it works part of the time!

Similar Threads

  1. vector causing system error/crash
    By babygal in forum Newbie
    Replies: 9
    Last Post: 21st October 2010, 08:48
  2. Qt 4.7 SSE2 causing my app to crash
    By jonks in forum Qt Programming
    Replies: 8
    Last Post: 26th September 2010, 19:53
  3. QThread::wait() causing crash
    By Olliebrown in forum Qt Programming
    Replies: 3
    Last Post: 24th September 2010, 16:24
  4. QTreeWidget->clear() causing crash after sort
    By Chuk in forum Qt Programming
    Replies: 7
    Last Post: 3rd September 2007, 10:59
  5. QProgressDialog::setValue crash( Mac )
    By marcel in forum Qt Programming
    Replies: 7
    Last Post: 12th April 2007, 00:12

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.