gpt4 book ai didi

c++ - QObject::connect timer with update() 函数

转载 作者:行者123 更新时间:2023-11-30 05:19:53 25 4
gpt4 key购买 nike

如何使用 QObject 将 void update(*p_1, *p_2, *p_3, *p_4, *scene) 函数与 timer() 连接: :连接?

我想要完成的是更新我已将指针传递到的对象并调用 *scene->update() 来刷新屏幕内容。

我有一个更新函数,如下所示:

void update(*p_1, *p_2, *p_3, *p_4, *scene){
// update functions
scene->update();
}

主要是我有:

int main(int argc, char **argv){
// creating objects and calculations
view.show();
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), update(&o_1, ..., &scene));
timer.start(1000);
return a.exec();
}

最佳答案

信号和函数的签名不兼容。因为如果那样,根据文档,您不能直接连接它们。
无论如何,您可以使用 lambda 来解决它:

QObject::connect(&timer, SIGNAL(timeout()), [&](){ update(&o_1, ..., &scene); }); 

关于c++ - QObject::connect timer with update() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40949905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com