Suppress warning “QApplication was not created in main() thread”

前端 未结 1 1840
伪装坚强ぢ
伪装坚强ぢ 2020-12-19 04:51

I\'ve created a Qt-based network library for use with applications that are not running a Qt event loop, and which are not necessarily otherwise Qt applications. This was ma

相关标签:
1条回答
  • 2020-12-19 05:14

    The problem arises because you're touching Qt APIs (in the main thread, or just in some thread) before creating QApplication. You can't do that. In particular, you're creating a QObject of some kind, which is setting somwhere in Qt what Qt itself should consider as the main thread.

    The only Qt APIs you're allowed to use before creating a QApplication are the ones that are explicitely documented to be safe in that scenario.

    So: don't do that. Build a QCoreApplication as the first thing, then you're free to go.

    0 讨论(0)
提交回复
热议问题