timer =new QTimer(this); timer->start(1000); connect(timer, &QTimer::timeout, this, &MainWindow::moveAgvs);,QTimer::singleShot(time, this, [&, i, next_node, cur_x, cur_y, power_consumption, j, steps]()設置爲,第一個qtime結束以後,再去運行第二個
时间: 2024-02-20 21:02:22 浏览: 31
这段代码中涉及到了两个不同的 QTimer,第一个 QTimer 是通过 timer->start(1000) 启动的,它的作用是每隔 1 秒钟触发一次 timeout 信号,然后调用 MainWindow 类的 moveAgvs() 函数。第二个 QTimer 是通过 QTimer::singleShot(time, this, [&, i, next_node, cur_x, cur_y, power_consumption, j, steps]()) 启动的,它的作用是在 time 毫秒之后触发一次 timeout 信号,然后执行 []() 中的 lambda 表达式。这两个 QTimer 是独立的,它们之间没有关联。
如果你想在第一个 QTimer 完成之后再去启动第二个 QTimer,可以在第一个 QTimer 的 timeout 信号中添加一个槽函数,在该槽函数中启动第二个 QTimer。例如:
```c++
void MainWindow::moveAgvs() {
// 处理第一个 QTimer 的 timeout 信号
...
// 第一个 QTimer 完成之后,启动第二个 QTimer
QTimer::singleShot(time, this, [&, i, next_node, cur_x, cur_y, power_consumption, j, steps]() {
// 处理第二个 QTimer 的 timeout 信号
...
});
}
```
这样就可以在第一个 QTimer 完成之后再去启动第二个 QTimer。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)