moveToThread vs deriving from QThread in Qt

前端 未结 4 1015
南笙
南笙 2021-02-01 17:07

When should moveToThread be preferred over subclassing QThread?

This link shows that both methods work. On what basis should I decide what to u

4条回答
  •  隐瞒了意图╮
    2021-02-01 17:25

    QThread is low level thread abstraction, first look at high level API QtConcurrent module and QRunnable

    If nothing of these is suitable for you, then read this old article, it tells how you should use QThread. Think about thread and task performed in this thread as a separate objects, don't mix them together.

    So, if you need to write come custom, specific or extended thread wrapper then you should subclass QThread.

    If you have QObject derived class with signals and slots, then use moveToThread on it.

    In other cases use QtConcurrent, QRunnable and QThreadPoll.

提交回复
热议问题