In Qt, application code Class Ahas one member method, for example method1(). I want to call this method in another member function method2()and run mehtod1()in another thread. But what I found from the qt documentation is below.
Class A
method1()
method2()
mehtod1()
class MyThread
QThread
run()
MyThread
But the above seems a bit complicated. Is there any mechanism in Qt so that I can immediately create a new one QThread(without inheritance) in mine method1()and start method2()with this thread, and then return to method1()after completion of execution?
Please let me know if I do not understand in my question.
Yes, there is a way how you want.
This article will help you understand why this is not the right way to inherit from QThread: http://blog.qt.digia.com/blog/2010/06/17/youre-doing-it-wrong/
In this article, you will learn how to use QThread really simple: http://blog.qt.digia.com/blog/2006/12/04/threading-without-the-headache/
You can use QObject slots and signals or event support in conjunction with streams.
, QObject, /, , QObject. QObject:: moveToThread.
QCoreApplication:: postEvent , .
QObjects Qt ( " QObjects" ).
, "" .