QT:必须在GUI线程中创建小部件
我面临这个问题,该问题在跑步一段时间后(几分钟)后,在看似随机的时间崩溃了我的基于QT的应用。
ASSERT failure in QWidget: "Widgets must be created in the GUI thread.", file kernel\qwidget.cpp, line 1145
甚至在哪里开始调试这个?即使尝试隔离我最近添加的新代码,以查看此问题是否持续存在证明是尚无定论的。
我有使用.UI文件生成显示的代码,我还可以在显示类中手动扩展使用类似的内容:
/* main widget */
QMainWindow* tmpQMainWindow = new QMainWindow();
ui.setupUi(tmpQMainWindow);
m_pDisplayWidget = tmpQMainWindow->centralWidget();
m_staticHandler.setPortGraphics(m_pPortGraphics);
...
/* Button for sensor input */
guiInfo.inputButton = new QPushButton(ui.mainBox);
guiInfo.inputButton->setObjectName(...);
guiInfo.inputButton->setText(...);
guiInfo.inputButton->setCheckable(true);
guiInfo.inputButton->setChecked(false);
ui.verticalLayout_4->addWidget(guiInfo.inputButton);
ui
对象在显示类中的标头文件中声明,例如:
/* GUI */
Ui::MainDisplayWindow ui;
并且简单地从文件ui_maindisplay.h
中获得,在顶部和自身自动生成的maindisplay.ui
中。
所以,是的,我们可能需要来回一些,因为我什至不知道要发布哪些其他信息。
提前致谢 !
I am facing this issue which crashes my Qt-based app at seemingly random times after running for a while (a few minutes).
ASSERT failure in QWidget: "Widgets must be created in the GUI thread.", file kernel\qwidget.cpp, line 1145
Where to even start to debug this ? Even trying to isolate new pieces of code that I recently added to see if this issue persists has proven inconclusive.
I have code to generate a display using a .ui file, which I also manually extend in the display class with things like this :
/* main widget */
QMainWindow* tmpQMainWindow = new QMainWindow();
ui.setupUi(tmpQMainWindow);
m_pDisplayWidget = tmpQMainWindow->centralWidget();
m_staticHandler.setPortGraphics(m_pPortGraphics);
...
/* Button for sensor input */
guiInfo.inputButton = new QPushButton(ui.mainBox);
guiInfo.inputButton->setObjectName(...);
guiInfo.inputButton->setText(...);
guiInfo.inputButton->setCheckable(true);
guiInfo.inputButton->setChecked(false);
ui.verticalLayout_4->addWidget(guiInfo.inputButton);
The ui
object is declared in the header file within the display class, like this :
/* GUI */
Ui::MainDisplayWindow ui;
and is simply obtained from the file ui_MainDisplay.h
, included at the top and itself auto-generated out of MainDisplay.ui
.
So yeah, we might need a bit of back and forth, because I don't even know what other infos to post.
Thanks in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不用介意,我们实际上已经有QT消息处理程序,它试图制作一个带有Infos和All的不错的碰撞对话框,并且它是 对话框,它使QT说无法在外面创建小部件。主线程。哪个,足够公平!
我知道过去的崩溃对话框,但是在这里似乎并没有出现 - 符合有关Qwidgets的错误消息。
我现在看到有一个
std :: bad_alloc
触发我们的崩溃处理过程的情况,但是bad_alloc
确实是它。那时我将私下调查。Never mind, we actually already have Qt Message Handler and it tries to produce a nice crash dialog box with infos and all, and it is this dialog box that brings Qt to saying that Widgets cannot be created outside of the main thread. Which, fair enough !
I know this crash dialog from the past, but here it doesn't appear at all it seems - in conformity with the error message about QWidgets.
I now see there is a case of
std::bad_alloc
which triggers our crash handling procedure, but thebad_alloc
is really what it is. I will investigate privately or elsewhere then.