Issue with Qt thread affinity and moveToThread

后端 未结 4 1834
长发绾君心
长发绾君心 2021-01-13 07:58

I\'m trying to use threads in Qt to delegate some work to a thread, but I can\'t get it to work. I have a class inheriting QMainWindow that have a member object that launch

4条回答
  •  臣服心动
    2021-01-13 08:38

    You can only use moveToThread in case when

    • Your object has no parent (because otherwise the parent will have different thread affinity)
    • You are on the object's owner thread so you actually 'push' the object from current thread to another

    So your error message says you're violating the second case. You should call moveToThread from the thread that created the object.
    And according to you

    This object has the QMainwindow as parent.

    So moveToThread will not work, again. You should remove the parent from m_poller object

提交回复
热议问题