如何使用QObject::connect
将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); });