0

私のコードには、qlabel を更新する次の関数があります。qlabel は非常に頻繁に更新されます。コードは

void foo::someMethod(std:atring a)
{
     {//begin
     boost::lock_guard<boost::mutex> lock(mutex_label);
     frm->mylabel->setText(a.c_str());
     }//end lock
}

そしてしばらくすると、アサーション エラーが発生します。

assert failure in documentRect: "document rect called for label that is not a text label! , file widgets\qlabel.cpp

それを引き起こしている可能性のある提案はありますか?また、値が表示されない場合もあります。値を更新するには、フォームを移動する必要があります

4

1 に答える 1

3

You cannot touch the GUI from another thread. No amount of mutexes will help here, Qt does not support that. The correct way is doing this via signals and slots.

You can read more at Qt signaling across threads, one is GUI thread? .

于 2013-04-17T16:00:49.127 に答える