Qt show() in boost coroutine function
-
I was trying to show a widget in boost coroutine, and called show() crashed.
Boost version is 1.83.0, Qt version is 5.15.2Here is my code:
QFile uiFile = QFile(QString("a.ui")); if (!uiFile.open(QIODevice::ReadOnly)) { return; } QUiLoader loader; QWidget* pWidget = loader.load(&uiFile); pWidget->show(); uiFile.close();
Here is call stack:
-
I was trying to show a widget in boost coroutine, and called show() crashed.
Boost version is 1.83.0, Qt version is 5.15.2Here is my code:
QFile uiFile = QFile(QString("a.ui")); if (!uiFile.open(QIODevice::ReadOnly)) { return; } QUiLoader loader; QWidget* pWidget = loader.load(&uiFile); pWidget->show(); uiFile.close();
Here is call stack:
@iamfly You must not access gui elements from outside the main thread.
-
You mean no possible to access qt widgets outside mainthread? Or how about use qt coroutine?
-
You mean no possible to access qt widgets outside mainthread? Or how about use qt coroutine?
@iamfly said in Qt show() in boost coroutine function:
You mean no possible to access qt widgets outside mainthread?
Yes. Do not modify UI outside of the main thread. Other threads can emit signals to trigger changes in the UI and pass data to it. In main thread you subscribe to these signals and modify the UI.
-
@iamfly said in Qt show() in boost coroutine function:
You mean no possible to access qt widgets outside mainthread?
Yes. Do not modify UI outside of the main thread. Other threads can emit signals to trigger changes in the UI and pass data to it. In main thread you subscribe to these signals and modify the UI.