Qt show() in boost coroutine function
-
wrote on 22 Feb 2024, 06:19 last edited by
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();
-
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:
Lifetime Qt Championwrote on 22 Feb 2024, 06:20 last edited by Christian Ehrlicher@iamfly You must not access gui elements from outside the main thread.
-
wrote on 22 Feb 2024, 07:15 last edited by
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.
1/5