Qiieha
21st May 2012, 16:56
Hi,
I have a MainWindow with a QTabWidget and a QPlainTextEdit. If I click on a button an Object is created and a Thread. The Object is moved to the thread and some signals and slots get connected:
BaseExport* creator = new BaseExport(NULL);
MyThread* mthread = new MyThread(NULL);
creator->moveToThread(mthread);
connect(creator,SIGNAL(new_status(QString)),this,S LOT(status_received(QString)),Qt::QueuedConnection );
connect(creator,SIGNAL(finished()),ui->progressBar,SLOT(hide()),Qt::QueuedConnection);
connect(creator,SIGNAL(finished()),creator,SLOT(de leteLater()),Qt::QueuedConnection);
connect(creator,SIGNAL(error(QString)),this,SLOT(e rror_received(QString)),Qt::QueuedConnection);
connect(creator,SIGNAL(more_than_one_result(QList<QList<SetField *> *> *)),this,SLOT(more_than_one_result_slot(QList<QList<MatchingSetField*>*>*)),Qt::QueuedConnection);
connect(this,SIGNAL(decided(QList<SetField*>*)),creator,SLOT(decided_slot(QList<SetField*>*)),Qt::QueuedConnection);
creator->connect(mthread,SIGNAL(started()),SLOT(create()));
connect(creator,SIGNAL(finished()),mthread,SLOT(qu it()));
connect(mthread,SIGNAL(finished()),mthread,SLOT(de leteLater()));
mthread->start();
Everything works fine. The create Slot of my Object starts and do some work. The signals (new_status, error) are received and the guithread shows the status and the errors.
It works to the point where the creator object in the thread need some information from the user. The object emits the signal more_than_one_result(). The receiving slot opens a QDialog with a table, which shows the results.
After choosing a result, the Mainthread emits the signal decided and sends a QList back to the thread.
The thread waits for the response in an QEventLoop waitloop;
In the slot decided_slot the waitloop ends with the call waitloop.quit(). And there sometimes occurs the error:
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
and the app crashes.
What's wrong? Maybe somebody can give me a hint. Thank u
I have a MainWindow with a QTabWidget and a QPlainTextEdit. If I click on a button an Object is created and a Thread. The Object is moved to the thread and some signals and slots get connected:
BaseExport* creator = new BaseExport(NULL);
MyThread* mthread = new MyThread(NULL);
creator->moveToThread(mthread);
connect(creator,SIGNAL(new_status(QString)),this,S LOT(status_received(QString)),Qt::QueuedConnection );
connect(creator,SIGNAL(finished()),ui->progressBar,SLOT(hide()),Qt::QueuedConnection);
connect(creator,SIGNAL(finished()),creator,SLOT(de leteLater()),Qt::QueuedConnection);
connect(creator,SIGNAL(error(QString)),this,SLOT(e rror_received(QString)),Qt::QueuedConnection);
connect(creator,SIGNAL(more_than_one_result(QList<QList<SetField *> *> *)),this,SLOT(more_than_one_result_slot(QList<QList<MatchingSetField*>*>*)),Qt::QueuedConnection);
connect(this,SIGNAL(decided(QList<SetField*>*)),creator,SLOT(decided_slot(QList<SetField*>*)),Qt::QueuedConnection);
creator->connect(mthread,SIGNAL(started()),SLOT(create()));
connect(creator,SIGNAL(finished()),mthread,SLOT(qu it()));
connect(mthread,SIGNAL(finished()),mthread,SLOT(de leteLater()));
mthread->start();
Everything works fine. The create Slot of my Object starts and do some work. The signals (new_status, error) are received and the guithread shows the status and the errors.
It works to the point where the creator object in the thread need some information from the user. The object emits the signal more_than_one_result(). The receiving slot opens a QDialog with a table, which shows the results.
After choosing a result, the Mainthread emits the signal decided and sends a QList back to the thread.
The thread waits for the response in an QEventLoop waitloop;
In the slot decided_slot the waitloop ends with the call waitloop.quit(). And there sometimes occurs the error:
QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
and the app crashes.
What's wrong? Maybe somebody can give me a hint. Thank u