在子線程中調用主線程的函數,函數中有更改變量的操作,就出現了這個問題:cannot create children for a parent that is in a different thread.
原因:在 QT 中,當使用多線程時,只要有更改主線程變量的操作,都會出現該問題。解決這個問題的標準方法是使用信號和插槽。
參考鏈接:
https://stackoverflow.com/questions/3268073/qobject-cannot-create-children-for-a-parent-that-is-in-a-different-thread
但是,子線程如果傳一個對象給主線程呢?信號只能發送 int 和 str 類型的數據。