Commit Graph

2 Commits

Author SHA1 Message Date
Marco Bubke
86e2426ac6 QmlDesigner: Improve ownership of text editor
Handling raw pointer can easily lead to mistakes. So it's better to
remove unique pointer. In this case a deleteLater pointer is added.

The pointer has not be tested for null  because of:

23.11.1.2.2 unique_ptr destructor [unique.ptr.single.dtor]

2 Effects: If get() == nullptr there are no effects. Otherwise
get_deleter()(get()).

Change-Id: I97eeb86b7316fc93fbed89707644ab7dde7f89f6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
2023-04-17 14:59:38 +00:00
Marco Bubke
48ad79ee1e Utils: Introduce UniqueObjectPtr
We very often want to remove a Qobject in a scope but because it has a
parent it can be deleted earlier. So using std::unique_ptr can lead to
double deletion. UniqueObjectPtr can track if a pointer is already
deleted. So no double deletion is possible but we still delete the
object in that scope. UniqueObjectPtr is based on std::unique_ptr but
uses a QPointer as internal pointer representation.

Because QPointer is not convertable you cannot cast from one type to
an other(QTBUG-112464). Because of that UniqueObjectInternalPointer
derives from QPointer and adds a conversion constructor.

Change-Id: I2c7707489f6db836cc5db2463efa8c33932b6455
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
2023-04-03 12:48:11 +00:00