Custom widget crash in Designer if derived from QMainWindow
-
Dear all,
I am using some custom widgets in designer plugins, that are derived from QMainWindow. This custom widget then consists of a small toolbar and a layouted set of widgets as centralWidget.
In the last years, we could use these widgets in ui-files and create and modify them in QtDesigner using Qt5.
However, with Qt6.4.1, the Designer crashes if such a widget is dropped to any ui canvas. I started debugging this and have seen, that a QMainWindowContainer is created in the Designer for this custom widget, since it is derived from QMainWindow. The methodint QMainWindowContainer::currentIndex() const
is then called whenever the widget is dropped to the ui or if an existing widget is clicked and modified. This method returns 0, since no central widgets for the main window are placed within the Designer, since they are already created in the constructor of the custom widget itself. Therefore, currentIndex() returns 0, since a centralWidget is available. Nevertheless the member m_widgets of QMainWindowContainer contains zero items. Then, the crash occurs in the method
QWidget *QMainWindowContainer::widget(int index) const
where the lookup m_members.at(index) will fail. For Qt5, this fails in Debug due to the Q_ASSERT_X in the .at(...) method of m_members, however it runs in a Release build due to the implementation of the at method. This changed in Qt6, such that an error is raised both for Debug and Release.
Possibly, the QMainWindowContainer::widget should also return nullptr if the index is higher than the size of the m_members method.
Two questions:
- Does anybody know this kind of problem
- Is it desired and allowed to generate a custom widget, that can be used in the Designer, and which is derived from QMainWindow? Or is there any other workaround?
Thank you very much