Set priority to GUI thread in Qt

前端 未结 1 926
别跟我提以往
别跟我提以往 2021-01-17 12:23

Is it possible to set priority to the main GUI thread so it has higher priority comparing to the other threads (QThread)?

My aim is to not to freeze up the GUI while

相关标签:
1条回答
  • 2021-01-17 13:02

    Change the priority of the current thread when the current thread is the gui thread:

    int main(int argc, char ** argv) {
      QApplication app(argc, argv);
      QThread::currentThread()->setPriority(QThread::HighPriority);
      ...
    }
    

    You can submit the change from any other thread, too – as long as the main (GUI) thread has a running event loop:

    QMetaObject::invokeMethod(qApp, []{
      QThread::currentThread()->setPriority(QThread::HighPriority);
    });
    
    0 讨论(0)
提交回复
热议问题