Qt uses implicit sharing in some classes. So it does for QString:
Foo::Foo()
{
a
->setData
(QString("Hello world"));
}
Foo::~Foo()
{
// a gets destroyed and so also the string since a takes care of that. (And it the reference count is equal 0.
}
Foo::mySlot()
{
QString s
= a
->data
()->toString
();
// s is not a real copy (as long as you don't change it } // s gets deleted (or the reference count gets decreased.
Foo::Foo()
{
QAction *a = QAction(this);
a->setData(QString("Hello world"));
}
Foo::~Foo()
{
// a gets destroyed and so also the string since a takes care of that. (And it the reference count is equal 0.
}
Foo::mySlot()
{
QString s = a->data()->toString(); // s is not a real copy (as long as you don't change it
} // s gets deleted (or the reference count gets decreased.
To copy to clipboard, switch view to plain text mode
Bookmarks