2013-05-22 32 views
0

在同一类中的后台线程中可能调用方法吗?在没有C++的情况下使用C++/QT 11。 或者连续5秒运行foo2。在其他线程中调用方法QT/C++

class MyClass 
{ 
    public: 
    void foo(...) 
    { 
     // in another thread run foo2 
     foo2; 
    } 
    . 
    . 
    . 
    protected: 
    void foo2(...){} 

} 

感谢

回答

4

在一个单独的线程中运行某些功能,您可以使用QtConcurrent::run(我QFutureWatcher使用它)。与你想在你的线程发生的东西,运行每5秒左右吧,用QElapsedTimer

QFuture<void> future = QtConcurrent::run(this, &MyClass::foo2, ...foo2 arguments); 

http://qt-project.org/doc/qt-4.8/qtconcurrentrun.html#run或点击此处查看https://stackoverflow.com/search?q=QtConcurrent%3A%3Arun

,或者你也可以继承的QThread,重新实现的run(),然后创建线程的一个实例并在其上调用start()。

相关问题