void myDialog::on_pushButton_5_clicked() { QProgressDialog dialog(tr("文件复制进度"), tr("取消"), 0 ,50000, this); dialog.setWindowTitle(tr("文件复制进度条")); dialog.setWindowModified(Qt::WindowModal); dialog.show(); for(int i = 0; i < 50000; i++) { //设置进度条当前值 dialog.setValue(i); //避免界面冻结 QCoreApplication::processEvents(); //如果按了取消,怎提前中断 if(dialog.wasCanceled()) break; } //这样在才能显示100% dialog.setValue(50000); qDebug() << tr("文件传输结束"); }