Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ QtGUI水平滑块设置值与QeReleasdTimer_C++_Raspberry Pi_Qtgui_Qtonpi - Fatal编程技术网

C++ QtGUI水平滑块设置值与QeReleasdTimer

C++ QtGUI水平滑块设置值与QeReleasdTimer,c++,raspberry-pi,qtgui,qtonpi,C++,Raspberry Pi,Qtgui,Qtonpi,我有一个GUI按钮,可以调用shell脚本来开始录制视频。此外,我想要一个滑块来显示录制进度(最长录制时间为30秒)。我构建了以下功能: coid MainWindow::on_recordStart_clicked() { QElapsedTimer timer; QProcess *Prozess = new QProcess(); Prozess->start("record.sh"); timer.start(); for(;;) { ui->timelineLabel-&g

我有一个GUI按钮,可以调用shell脚本来开始录制视频。此外,我想要一个滑块来显示录制进度(最长录制时间为30秒)。我构建了以下功能:

coid MainWindow::on_recordStart_clicked()
{
QElapsedTimer timer;
QProcess *Prozess = new QProcess();
Prozess->start("record.sh");
timer.start();
for(;;)
{
ui->timelineLabel->setText(QString::number(timer.elapsed())); //label
ui->timeLine->setValue(timer.elapsed());  //slider
if (timer.hasExpired(30000)) break;
}
它仅在中断后更新滑块和标签。有人知道原因吗?

您的主(UI)线程正忙于迭代for循环,无法处理事件以更新标签

有一种快速且不干净的解决方案(未测试),请在
setValue
之后添加以下行:

QCoreApplication::processEvents();
更好的解决方案是将进程处理移动到一个单独的线程,并通过信号/插槽通知主线程进度