c++ - Updating a QT object from multiple OS threads -


i have existing multithreaded application i'm trying slap simple qt gui onto front end of.

in particular, i've tried implement simple log using qplaintextedit object. whenever 1 of these os threads kicks off action, i'm putting diagnostic info in widget call appendplaintext() method.

of course first crack @ had synchronization issues, created class wrapping qplainedit mutex synchronize things. this:

class synced_output { public:     std::mutex mutex;     qplaintextedit & text;      synced_output (qplaintextedit * text_output) : text(*text_output) {}     void put_line (const std::string & line) {         std::lock_guard<std::mutex> lock(mutex);          text.appendplaintext(line.c_str());     } private:     synced_output operator= (synced_output &){} }; 

that seems have fixed race condition nicely. however, contents of plaintextedit widget not visibly update until go interact window in way (merely clicking suffices). if adds enough text, can see scrollbar come , move around, no text until click.

based on advice saw online, tried putting text.repaint() in there, causes crash complaining "cannot send events objects owned different thread". makes sense suppose, still need so. how can display after change? there other better idiom handling qt calls change widget contents multiple os threads?


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -