Forum
Sign Up

dont use naked pointers, please use QPointer to store weak references

5 years 8 months ago #1 by Andres Kruse
Guys, another crash which could be avoided..

QtnRibbonTitleBarWidgetPrivate has a pointer to the RibbonBar.

I found that when closing the app it would crash with a problem in RibbonTitleBarWidget::topWidget() which was caused by the RibbonBar having been deleted already when another QEvent::WinIdChange came along.

I changed the naked pointer to a QPointer<RibbonBar> and then in the topWidget() method I checked if m_ribbonBar is non-zero first. Easy.

So, why do you use naked pointers to store references to your own stuff when it's so easy to add a bit of stability to your code by using QPointer<> and then testing whether the object is actually still there? You should only store a naked pointer if the object is *owned* and will be destroyed *before* the object that is pointing to it. In all other cases, use a QPointer<> if you can.

Same problem in RibbonToolBarActionGroupItem where you are storing a naked pointer to objects that are *not* owned by you, i.e. action and widget. Same fix as above to fix crashes in RibbonToolBarControlPrivate::calculateSizeHint and RibbonGalleryControl::sizeHint.

Please Log in or Create an account to join the conversation.

More
  • Not Allowed: to create new topic.
  • Not Allowed: to reply.
  • Not Allowed: to edit your message.
Moderators: Developer Machines
Time to create page: 0.114 seconds

Developer Newsletter

Join our Developer Machines newsletter to get informed on all the latest releases of the commercial components for Qt.C++, Delphi FireMonkey, updates and general knowledges.

Quick Support

Should you need any additional information about our products or licensing, please contact us at the following email addresses:

  • support@devmachines.com

  • license@devmachines.com

Get in Touch

If you would like to purchase our products or services, but don’t know how to do it the right way, please feel free to contact us:

  • support@devmachines.com( any questions related to our products or services )
  • license@devmachines.com( questions related to licensing )