2
我試圖在我的應用程序狀態欄上顯示一些連接/斷開連接的消息。它是一個用C++編寫的控制檯應用程序,帶有Qt GUI。當連接狀態發生變化時,連接處理程序會調用一個回調函數(在某些GUI相關對象中),它會更新GUI。我可以繪製我的QGraphicsScene,但是當我嘗試使用QStatusBar的showMessage方法時,它有時會立即崩潰,有時它會一直工作到幾次調用(但消息在超時後消失)。我收到此錯誤消息:在不同線程的回調中在狀態欄上顯示消息
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QStatusBar(0xae55feb0), parent's thread is QThread(0xb3e006f0), current thread is QThread(0xb0c00478)
QObject::startTimer: QTimer can only be used with threads started with QThread
QPixmap: It is not safe to use pixmaps outside the GUI thread
我認爲這意味着showMessage不會從GUI線程調用。那我怎麼能在狀態欄上顯示連接狀態的變化?
你是否真的從另一個線程調用它? –
是的,我確實,連接管理器運行在不同的線程中。 – gberes