当前位置:网站首页>QT thread and interface

QT thread and interface

2022-06-11 00:49:00 Yutian Dudu

Read an open source library Stacer, It's used inside QConcrrent, This is very convenient to use , Here is a brief record and summary Qt Thread creation method .

Qt Thread creation method

  1. QThread Inherit
  2. QObject  moveToThread
  3. QConcurrent::run

Qt If threads are mentioned in, we have to talk about the relationship between threads and interface components .

Threads and interface components

  • stay QT in , All interface component related operations must be in the main thread ( That is to say GUI thread), stay Qt Cannot create directly in the program thread QWidget Interface components like that , Nor can you directly operate interface components .

QThread How do threads operate interface components

Method 1

         Bind the signal and... Of the thread object UI The slot of the object , Send in thread emit The signal .

Method 2

         Inherit QEvent class , Use QApplication::postEvent() To send events to the interface

Method 3

          Use it directly Invokes() Function to call the signal slot of the interface component object ,( Can be used to call UI Private signal or slot of the object ):

原网站

版权声明
本文为[Yutian Dudu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206102333111564.html