GUI thread detecting in the Qt library

后端 未结 1 1121
轮回少年
轮回少年 2021-02-19 00:55

I need to know in the context of which thread my function is running, is it main GUI thread or some worker thread.

I can\'t use a simple solution to store QThread pointe

相关标签:
1条回答
  • 2021-02-19 01:54

    If you have Qt in the lib you can ask for the thread of the application object. The application object is alway living in the main gui thread.

    void fooWorker()
    {
        const bool isGuiThread = 
            QThread::currentThread() == QCoreApplication::instance()->thread();
    
    }
    
    0 讨论(0)
提交回复
热议问题