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.