Qtimer iterations
Qtimer iterations
本文关键字:iterations Qtimer 更新时间:2023-10-16
也许我想多了,但需要一些迭代和qtimer方面的帮助。我有以下QTimer代码和函数(我试图尽可能简化它,如果某些语法错误,对不起):
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(whateverfunction()));
timer -> start();
void MainWindow::whateverfunction()
{
checksomething();
if (checksomething() == 1)
{
dosomething1(); //function I want to run ONLY the first time checksomething() = 1
dosomething2(); //function I want to run the second,third,fourth,etc. time checksomething() = 1
}
else
{
donothing(); //if this function is run the count resets, meaning dosomething1() should be run again if checksomething() == 1 again-- but only the first time.
}
}
我怎样才能完成上述任务?我尝试引入一个控制变量,但每次通过 QTimer 运行此函数时,它都会重置。谢谢!
我建议用 std::call_once 来包装对dosomething1()
的调用
std::once_flag flag;
void MainWindow::whateverfunction()
{
checksomething();
if (checksomething() == 1)
{
std::call_once(flag, [this](){
dosomething1();
};
dosomething2();
}
}
相关文章:
- 如何从其他类n个Qt C++调用QTimer?
- 如何完全停止QTimer
- QTimer 超时不会在单元测试中触发
- 使用 QTimer、QThread 和进度条
- 在C++中使用std或boost库的Qtimer等价物是什么
- QTimer::singleShot 仅在间隔为 0 时调用 lambda
- 如何在QtConcurrent::run中启动QTimer或为什么QVector<QTimer*>不起作用
- 何时使用多个函数调用和 QTimer 调用析构函数?
- 使用 std::bind 将 QTimer::singleShot 传递给 std::async
- QTimer isActive 返回 true,但 remainingTime 返回 -1
- 让 QtConcurrent 中的 QTimer 正常工作
- QTimer timeout()方法不再在代码重组后启动
- QTimer 在传递变量时不会启动
- 在插槽中停止QTIMER
- 使用 QTimer 对包含 5 张图像的幻灯片进行计时
- 另一个应用程序用 c++ 在 Windows 上的线程中破坏 QTimer
- QTimer 线程的方法 'isActive()' 是安全的吗?
- 识别哪种QTIMER的任何方法
- QTimer超时信号在每个超时事件中多次发射
- Qtimer iterations