2016-12-03 24 views
1

如何使用QObject::connect連接void update(*p_1, *p_2, *p_3, *p_4, *scene)函數與timer()QObject ::使用update()函數的連接計時器

我想完成的是更新我已經通過指針的對象並調用*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(); 
} 
+0

這是它是如何應該做:http://doc.qt.io/qt-5/qtwidgets-graphicsview-collidingmice- example.html#the-main-function – user5292408

回答

1

信號的特徵和功能並不兼容。因爲如果那樣,根據文檔,你不能直接連接它們。
無論如何,你可以使用lambda來解決它:

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

問題是計時器和更新不是類的一部分。在創建適當的課程後,兩個問題都消失了。 – user5292408

相關問題