我程序中有一个计算模块会很耗时,造成界面假死,我把计算模块放到了一个新的线程中,但是想通过一个进度条来告诉用户计算模块处理数据的进度,但是貌似进度条在主线程中,也就是GUI线程才能用,不知道怎么才能让进度条能实时显示计算进度.
------解决思路----------------------
信号与槽,或者使用postEvent发送时间给GUI线程。
------解决思路----------------------
Because of limitations inherited from the low-level libraries on which Qt's GUI support is built, QWidget and its subclasses are not reentrant. One consequence of this is that we cannot directly call functions on a widget from a secondary thread. If we want to, say, change the text of a QLabel from a secondary thread, we can emit a signal connected to QLabel::setText() or call QMetaObject::invokeMethod() from that thread. For example:
void MyThread::run()
{
...
QMetaObject::invokeMethod(label, SLOT(setText(const QString &)),
Q_ARG(QString, "Hello"));
...
}