my main program:
MyMDIMainWindowThread* mainthread = new MyMDIMainWindowThread();
mainthread->start();
mainthread->wait();
return a.exec();
QApplication a(argc,argv);
MyMDIMainWindowThread* mainthread = new MyMDIMainWindowThread();
mainthread->start();
mainthread->wait();
return a.exec();
To copy to clipboard, switch view to plain text mode
MyMDIMainWindowThread run:
void MyMDIMainWindowThread::run()
{
mpMyMainWindow = new MyMDIMainWindow();
mpMyMainWindow->showMaximized();
qApp->setMainWidget(mpMyMainWindow);
std::cout << "mainthread ended" << std::endl << std::flush;
}
void MyMDIMainWindowThread::run()
{
mpMyMainWindow = new MyMDIMainWindow();
mpMyMainWindow->showMaximized();
qApp->setMainWidget(mpMyMainWindow);
std::cout << "mainthread ended" << std::endl << std::flush;
}
To copy to clipboard, switch view to plain text mode
run function for thread for the lengthy process:
// ... run lengthy process
//.. mpParent is set in the constructor and is a pointer to the widget that started the thread
qApp->postEvent(mpParent, new QCustomEvent(MyThread::PROCESSTHREADENDED));
// ... run lengthy process
//.. mpParent is set in the constructor and is a pointer to the widget that started the thread
qApp->postEvent(mpParent, new QCustomEvent(MyThread::PROCESSTHREADENDED));
To copy to clipboard, switch view to plain text mode
customEvents function:
void MyLengthyProcessWidget
::customEvent(QEvent* e
) {
switch (int(e->type()))
{
case MyThread::PROCESSTHREADENDED:
{
// the messagebox is never shown!
setEnabled(true);
break;
}
}
void MyLengthyProcessWidget::customEvent(QEvent* e)
{
switch (int(e->type()))
{
case MyThread::PROCESSTHREADENDED:
{
// the messagebox is never shown!
QMessageBox::critical(0, tr(""),tr("Process Thread Ended!!!"), QMessageBox::Ok,0,0);
setEnabled(true);
break;
}
}
To copy to clipboard, switch view to plain text mode
finally: starting the lengthy process thread from a function in MyLengthyProcessWidget::
setEnabled(false);
MyLengthyProcessThread* proc = new MyLengthyProcessThread(this);
proc->start();
setEnabled(false);
MyLengthyProcessThread* proc = new MyLengthyProcessThread(this);
proc->start();
To copy to clipboard, switch view to plain text mode
Think that's all....
Bookmarks