Details
-
Bug
-
Resolution: Fixed
-
P4: Low
-
6.4.1
-
None
-
-
177c70253 (dev), 0ff8b0eae (6.5), c4995f7af (tqtc/lts-6.2)
Description
If a widget, created in a custom designer plugin and derived from QMainWindow, is dragged and dropped to a canvas in the Qt Designer or if such a widget is clicked / changed, the Qt Designer crashes in Release build.
The crash itself occurs inĀ
QWidget *QMainWindowContainer::widget(int index) const
in the line
m_members.at(index)
since index is 0 and m_members.size() is 0 as well.
This bug is also contained in Qt5, however an assert is only raised in Debug build for both Qt5 and Qt6 and due to a changed implementation of the at operator of QList, this out-of-bounds indexing only crashes with Qt6.
What happend?
If a widget is dropped to the canvas, that is derived from QMainWindow, the wrapper class QMainWindowContainer is created. This should probably allow the situation that an empty QMainWindow is used in a ui-file, and one starts to put new widgets or actions in its central area or the menu or toolbars. In this case, if any new widget or action is added, it is added at runtime to the mentioned member m_members of QMainWindowContainer.
However, in the case of a ready to used plugin widget, the centralWidget of this widget, derived from QMainWindow, usually already contains a central widget, but the member m_members does not contain any values.
The method
int QMainWindowContainer::currentIndex() const
returns 0, since the centralWidget is set and unqual to nullptr. In this case, in
QWidget *FormWindow::innerContainer(QWidget *outerContainer) const
the currentIndex is obtained from QMainWindowContainer, that returns 0 in this case.
In a next step, container->widget(currentIndex) is called, that crashes with the mentioned error.
Possible solution:
One possible solution would be to change the method
QWidget *QMainWindowContainer::widget(int index) const { if (index == -1) return nullptr; return m_widgets.at(index); }
into
QWidget *QMainWindowContainer::widget(int index) const { if (index == -1 || index <= m_widgets.size()) return nullptr; return m_widgets.at(index); }
Thank you very much!