在QT中以不同的时间间隔更新GUI
Update GUI at different time interval in QT
我想知道如何在QT中的不同时间间隔更新GUI,最好的是我可以控制时间间隔。我知道QTimer可以在同一时间间隔更新GUI,但我需要控制时间间隔并将其设置为不同的值。
我需要使用多线程吗?
我尝试了pyqt,但失败了,请参阅"ui_mainwindow';对象没有属性';connect';"
以下是我将如何实现它,在MainWindow
的类中,定义一个将QLabel
设置为下一个映像的插槽:
void MainWindow::NextImage(){
switch(currentImageNo){
case 0:
//set 1st image
break;
case 1:
//set 2nd image
break;
case 2:
//set 3rd image
break;
...
}
timer.setInterval( /*your desired new interval based on currentImageNo*/ );
currentImageNo++;
//in order to loop back to the first image after the last image is shown
currentImageNo= currentImageNo % numberOfImages;
}
在MainWindow
的构造函数中,创建一个具有所需间隔的QTimer
,并将其timeout()
信号连接到上定义的NextImage
插槽
MainWindow::MainWindow(){
...
timer= new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(NextImage()));
timer.setSingleShot(false);
timer.setInterval(5000); //5 secs for first image
timer.start();
NextImage(); //to load the first image initially
}
请记住将currentImageNo
、numberOfImages
和timer
声明并初始化为MainWindow
类的成员。
相关文章:
- C++为构建时间获取QDateTime的可靠方法
- 从C++本机插件更新Vector3数组
- 从持续时间构造std::chrono::system_clock::time_point
- QGraphicsPolygonItem在拖动时未更新QPolygonF坐标
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- while循环中while循环的时间复杂度是多少
- 使用简单类型列表实现的指数编译时间.为什么
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- Chilkat SFTP 文件修改时间不与上传更新
- 如何在长时间计算中进行C 的一次进度更新
- 如何在一段时间内更新 QLabel?
- QT 上的 exe 文件在树莓派终端上的更新时间时挂起
- 自动更新QDateTimeEdit,以便它显示当前的系统日期和时间
- 给定一个微秒值,如何准确地得到一个时间值结构体?/*更新获取负值*/
- 在QT中以不同的时间间隔更新GUI
- 如何以预定的时间间隔更新 GUI,同时仍执行非 GUI 工作
- 如何在 c++ 程序中更新时间
- 时钟时间在 C++ 中未更新
- VTK:在每个模拟时间步长更新renderWindow中的数据点
- 在c++中使用GetTickCount()更新时间和位置