mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-04 00:04:03 -04:00
fix(QObjectUniquePtr): delete currently pointed object when moving
This commit is contained in:
parent
beb3e987f0
commit
f580afd7a6
@ -91,6 +91,7 @@ class QObjectUniquePtr
|
||||
|
||||
QObjectUniquePtr &operator=( QObjectUniquePtr &&other ) noexcept
|
||||
{
|
||||
delete mPtr.data();
|
||||
mPtr = other.mPtr;
|
||||
other.clear();
|
||||
return *this;
|
||||
|
@ -136,6 +136,18 @@ void TestQObjectUniquePtr::testVector()
|
||||
|
||||
QCOMPARE( objects.at( 0 )->objectName(), "TESTA" );
|
||||
QCOMPARE( objects.at( 1 )->objectName(), "TESTB" );
|
||||
|
||||
int nbObjectDestroyed = 0;
|
||||
auto onDestroyed = [&nbObjectDestroyed]() { nbObjectDestroyed++; };
|
||||
|
||||
connect( objects.at( 0 ), &QObject::destroyed, this, onDestroyed );
|
||||
connect( objects.at( 1 ), &QObject::destroyed, this, onDestroyed );
|
||||
|
||||
objects.erase( objects.cbegin() );
|
||||
|
||||
QCOMPARE( objects.size(), 1 );
|
||||
QCOMPARE( nbObjectDestroyed, 1 );
|
||||
QCOMPARE( objects.at( 0 )->objectName(), "TESTB" );
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user