Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Custom widget crash in Designer if derived from QMainWindow

Custom widget crash in Designer if derived from QMainWindow

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
designercustomwidgetqmainwindow
1 Posts 1 Posters 272 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    magro11
    wrote on 22 Feb 2023, 11:30 last edited by
    #1

    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 method

    int 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

    1 Reply Last reply
    0

    1/1

    22 Feb 2023, 11:30

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved