If the update should be initiated by another thread, you should create an event for that:
#define UPDATE_COUNT_EV QEvent::User
class UpdateCountEvent : public QEvent
{
public:
UpdateCountEvent(int err, int warn, int v) :
QEvent((QEvent::Type)UPDATE_COUNT_EV),
errCount(err),
warnCount(warn),
vCount(v)
{
}
int errCount;
int warnCount;
int vCount;
};
class MyDialog : public QDialog
{
void customEvent(QEvent *event);
};
void MyDialog::customEvent(QEvent *event)
{
if (static_cast<int>(event->type()) == UPDATE_COUNT_EV)
{
const UpdateCountEvent *ev = static_cast<const updatecountevent="">(event);
ui->listWidget->item(0)->setText(QString("Total Errors: %1").arg(ev->errCount));
ui->listWidget->item(1)->setText(QString("Total Warnings: %1").arg(ev->warnCount));
ui->listWidget->item(2)->setText(QString("Total Violations: %1").arg(ev->vCount));
}
}
</const></int>
The event can now be send from another thread (requires inclusion of the header that defines
UpdateCountEvent
and a pointer to the dialog widget):
QCoreApplication::postEvent(pDialogWidget, new UpdateCountEvent(ErrCount, WarnCount, VCount));
If you want to update only single values, create three events and update the list items in
MyDialog::customEvent
accordingly.