I am porting an application from QT3 to QT4, and keep running into problems when a thread is updating a QProgressDialog. The original code was roughly designed like so:
class ScanProcess : QObject{
Q_OBJECT
public:
QProgressDialog* progress;
private:
ScanProcessThread* thread;
};
class ScanProcessThread : QThread {
Q_OBJECT
public:
void run();
};
This is after running qt3to4 and making the appropriate changes from the QT Porting guide.
In the original design, inside the ScanProcessThread:
void ScanProcessThread::run(){
//...
ProgressInfo *prog = new ProgressInfo(); //then fill it in
QCustomEvent* progEvent = new QCustomEvent(QEvent::User+1, (void*)prog);
QCoreApplication::postEvent(parent, progEvent);//Parent is pointer to the ScanProcess
//...
}
void ScanProcess::customEvent(QCustomEvent *e){
if(e->type() == QEvent::User+1){
//update QProgressDialog
progres->setValue(prog.index);//Value from the ProgressInfo passed above
//This line crashes deep in ntdll, but I have traced it to the QProgressDialog::repaint()
}
}
struct ProgressInfo {int count; int index; QString text;};
So, that's the important code. The call to QProgressDialog::Repaint seems to always crash somewhere deep in ntdll. I have tried two other methods: 1) Use QCoreApplication::postEvent() 2) Pass the QProgressDialog* and let ScanProcessThread update it directly. In every case, it's the QProgressDialog::repaint() that fails. Any ideas?
(qt4.4, windows xp sp3, Visual Studio 2008/)