我正在尝试围绕现有的管理控制台应用程序包装 GUI。主要功能是搜索网络设备,给它一个超时,本质上是一个阻塞调用,直到超时到期(使用sleep来做阻塞)。在此示例中,调用是this->Manager->Search(...)
.
我的问题是我希望 QListWidget 在搜索发生时显示“正在搜索...”,然后在搜索完成时更新结果。我的按钮点击代码Search
如下:
void ManagerGUI::on_searchButton_clicked()
{
ui->IPList->clear();
new QListWidgetItem(tr("Searching..."), ui->IPList);
ui->IPList->repaint();
this->Manager->Search(static_cast<unsigned int>(this->ui->searchTime->value()*1000.0));
ui->IPList->clear();
if(this->Manager->GetNumInList() != 0)
this->displayFoundInList(this->Manager->GetFoundList());
else
new QListWidgetItem(tr("No Eyes Found"), ui->IPList);
ui->IPList->repaint();
}
当我点击按钮时,QListWidget
IPList
直到发生超时之后才会更新(我假设直到这个回调终止之后)。有没有人有什么建议?我的印象是调用ui->IPList->repaint()
会导致列表立即重绘。
附加信息:
- QT 版本 5.1.0 32 位
- 使用VS2012编译
- 在 Win7 Pro 64 位上运行(但要移植到 OSX 和 Linux,所以请不要特定于 win)