The QRunnable class is the base class for all runnable objects. 更多...
| 頭: | #include <QRunnable> |
| qmake: | QT += core |
| Since: | Qt 4.4 |
該類在 Qt 4.4 引入。
| QRunnable () | |
| virtual | ~QRunnable () |
| bool | autoDelete () const |
| virtual void | run () = 0 |
| void | setAutoDelete (bool autoDelete ) |
| QRunnable * | create (std::function<void ()> functionToRun ) |
The QRunnable class is an interface for representing a task or piece of code that needs to be executed, represented by your reimplementation of the run () 函數。
可以使用
QThreadPool
在單獨綫程中執行代碼。
QThreadPool
deletes the QRunnable automatically if
autoDelete
() 返迴
true
(默認)。使用
setAutoDelete
() 以改變自動刪除標誌。
QThreadPool supports executing the same QRunnable more than once by calling QThreadPool::tryStart (this) 從 run () 函數。若 autoDelete is enabled the QRunnable will be deleted when the last thread exits the run function. Calling QThreadPool::start () multiple times with the same QRunnable when autoDelete 被啓用會創建競爭條件且不推薦。
另請參閱 QThreadPool .
Constructs a QRunnable. Auto-deletion is enabled by default.
另請參閱 autoDelete () 和 setAutoDelete ().
[虛擬]
QRunnable::
~QRunnable
()
QRunnable 虛擬析構函數。
返迴
true
自動刪除被啓用;否則 false。
若自動刪除被啓用, QThreadPool 將自動刪除此可運行後於調用 run ();否則,所有權仍然屬於應用程序程序員。
另請參閱 setAutoDelete () 和 QThreadPool .
[static]
QRunnable
*QRunnable::
create
(
std::function
<
void
()>
functionToRun
)
創建 QRunnable that calls functionToRun in run ().
Auto-deletion is enabled by default.
該函數在 Qt 5.15 引入。
另請參閱 run () 和 autoDelete ().
[pure virtual]
void
QRunnable::
run
()
在子類中實現此純虛函數。
啓用自動刪除若 autoDelete 為 true;否則自動刪除被禁用。
若自動刪除被啓用, QThreadPool 將自動刪除此可運行後於調用 run ();否則,所有權仍然屬於應用程序程序員。
注意,必須設置此標誌先於調用 QThreadPool::start ()。調用此函數後於 QThreadPool::start () 將導緻未定義行為。
另請參閱 autoDelete () 和 QThreadPool .