在 C++ Qt 中的 for 循环中增加进度条
increment progress bar inside for loop in c++ Qt
我是 Qt 的新手,我想在 for 循环中的进度条中显示一些进度,
进度条应显示从 0 到 100 的进度
怎么办,请帮忙谢谢。
QProgressBar bar;
for(int i = 0; i < 100; ++i)
{
bar.setValue(i);
}
来自文档(例如 http://doc.qt.io/qt-4.8/qprogressbar.html)
A progress bar is used to give the user an indication of the progress of an operation [...]
You can specify the minimum and maximum number of steps with setMinimum() and setMaximum. The current number of steps is set with setValue().
所以你需要构造一个QProgressBar
对象,指定最小值和最大值,然后调用setValue(int value)
让它前进。
针对您的情况:
QProgressBar progressBar;
progressBar.setMinimum(0);
progressBar.setMaximum(100);
// or as alternative to the two above, you could call
// progressBar.setRange(0,100);
for( int i = 0; i <100; ++i ) {
progressBar.setValue(i);
}
我是 Qt 的新手,我想在 for 循环中的进度条中显示一些进度, 进度条应显示从 0 到 100 的进度 怎么办,请帮忙谢谢。
QProgressBar bar;
for(int i = 0; i < 100; ++i)
{
bar.setValue(i);
}
来自文档(例如 http://doc.qt.io/qt-4.8/qprogressbar.html)
A progress bar is used to give the user an indication of the progress of an operation [...]
You can specify the minimum and maximum number of steps with setMinimum() and setMaximum. The current number of steps is set with setValue().
所以你需要构造一个QProgressBar
对象,指定最小值和最大值,然后调用setValue(int value)
让它前进。
针对您的情况:
QProgressBar progressBar;
progressBar.setMinimum(0);
progressBar.setMaximum(100);
// or as alternative to the two above, you could call
// progressBar.setRange(0,100);
for( int i = 0; i <100; ++i ) {
progressBar.setValue(i);
}