当我点击MainWindow的按钮时,我正在使用QProgressBar创建新窗口但是当创建新窗口时,QProgressBar在填充循环工作时不会出现。然后QProgressBar出现并填满。
构造
ProgressWin::ProgressWin():QWidget()
{
this->resize(273,98);
this->move(670, 430);
bar1 = new QProgressBar(this);
bar1->setGeometry(20, 31, 251, 31);
bar1->setMinimum(0);
bar1->setMaximum(10000);
this->show();
unsigned long long secr, PQ;
unsigned long long rv;
unsigned long long decr;
for(int v = 0; v <= 100000; v++) {
bar1->setValue(v);
}
}
调用新窗口的按钮代码:
void RsaMainWindow::ButtClickCrypt()
{
FileName1 = ui->LineCrypt->text();
if(FileName1.isEmpty()) {
QMessageBox::information(0, "Information", "File for Crypt wasn't chosen");
return;
}
NewWin = new ProgressWin;
}
新窗口类:
class ProgressWin : public QWidget
{
QProgressBar *bar1;
public:
ProgressWin();
};
MainWindow的类:
[namespace Ui {
class RsaMainWindow;
}
class RsaMainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit RsaMainWindow(QWidget *parent = 0);
~RsaMainWindow();
private slots:
void ButtClickViewCryp();
void ButtClickViewDecr();
void ButtClickViewKeys();
void ButtClickCrypt();
void ButtClickDecr();
private:
Ui::RsaMainWindow *ui;
QString FileName1;
QString FileName2;
QString FileName3;
ProgressWin *NewWin;
};][1]
答案 0 :(得分:0)
用户界面通常适用于事件循环原则:
While (not closing the app)
Wait for some event
update app according event
endWhile
如果您在GUI线程中执行繁重的任务,当用户单击“执行繁重的任务”时,将调用管理此单击的代码,完成后,以下事件将触发窗口的绘制。这意味着您的繁重任务将在任务期间冻结用户界面。
要正确执行繁重的任务,您需要: