久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在不同的 QT 線程中創建窗口?

How do I create a Window in different QT threads?(如何在不同的 QT 線程中創建窗口?)
本文介紹了如何在不同的 QT 線程中創建窗口?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個應用程序,其中每個線程(主線程除外)都需要創建自己的窗口.我嘗試創建一個線程,然后在 run 函數中調用 this->exec() .但是,我什至在調用之前收到一個錯誤:ASSERT 在 QWidget 中失敗:Widgets must be created in the GUI thread."

I have an application in which each thread (except the main thread) needs to create its own window. I tried creating a thread and then calling this->exec() in the run function. However, I get an error before I even get to that call: ASSERT failure in QWidget: "Widgets must be created in the GUI thread."

我想彈出一個消息窗口.問題是源有多個線程,每個線程可能需要彈出自己的消息.

I want to popup a message window. The problem is that the source has multiple threads each of which may need to popup its own message.

推薦答案

如果你需要在不同的(非主)線程中創建 QWidget(或其他一些 gui 組件),你可以在這樣的線程中實現它方式:

If you need to create QWidget(or some other gui component(s)) in different(non-main) thread(s) you can implement it in such way:

  • 創建包含 gui 組件的簡單包裝器:

  • Create simple wrapper which holds gui component:

// gui component holder which will be moved to main thread
class gui_launcher : public QObject
{
  QWidget *w;
  // other components
  //..
public:
  virtual bool event( QEvent *ev )
  {   
    if( ev->type() == QEvent::User )
    {
      w = new QWidget;
      w->show();
      return true;
    }
    return false;
  }
};

  • 在主線程中創建QApplication對象

  • create QApplication object in main thread

    另一個線程主體:

    ..
      // create holder
      gui_launcher gl;
      // move it to main thread
      gl.moveToThread( QApplication::instance()->thread() );
      // send it event which will be posted from main thread
      QCoreApplication::postEvent( &gl, new QEvent( QEvent::User ) );
    ..
    

  • 開心點,:)

  • be happy, :)

    這篇關于如何在不同的 QT 線程中創建窗口?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

    【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!
  • 相關文檔推薦

    How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
    In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
    How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
    Reusing thread in loop c++(在循環 C++ 中重用線程)
    Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
    Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
    主站蜘蛛池模板: 欧美一区免费 | 久久国产精品视频观看 | 亚洲精品久久久一区二区三区 | 欧美日韩三级在线观看 | 毛片免费看的 | 日韩色视频 | 蜜臀久久99精品久久久久久宅男 | 亚洲综合天堂 | 亚洲精久久 | 一区二区久久 | 成人免费网站视频 | 欧美成人激情视频 | 99久久久久国产精品免费 | 91精品国产综合久久香蕉922 | .国产精品成人自产拍在线观看6 | 国产不卡一区 | 在线观看的av| 中文字幕亚洲区一区二 | 国产精品九九九 | 黄色大片视频 | 国产激情福利 | 亚洲精品一区二区三区丝袜 | 国产精品99 | 最新中文字幕 | 久久综合入口 | 草樱av| 国产精品久久久久久福利一牛影视 | 国产免费播放视频 | 古装三级在线播放 | 在线观看国产 | 欧美视频免费在线 | av男人的天堂av | 久久精品国产亚洲夜色av网站 | 久久成人精品视频 | 精品日韩| 日本中文字幕一区 | 欧美一区二区免费视频 | 免费亚洲成人 | 久久久精品一区二区 | 91久久 | 亚洲a网|