[Qt-interest] QList and QUrl problem
ice stone
icestone6124 at yahoo.com
Fri Mar 26 15:01:14 CET 2010
Thank you for the detailed explanation. I see that setUrl is the culprit. So for now I will just create a new QUrl object for appending each time.
Yan
--- On Fri, 3/26/10, Denis Akhmetzyanov <dakhmetzyanov at smartlabs.tv> wrote:
From: Denis Akhmetzyanov <dakhmetzyanov at smartlabs.tv>
Subject: Re: [Qt-interest] QList and QUrl problem
To: "ice stone" <icestone6124 at yahoo.com>
Cc: qt-interest at trolltech.com
Date: Friday, March 26, 2010, 8:18 AM
Hi,
QUrl class is implicit sharing and QUrl::setUrl() method internally doesn't call to detach() (review src of Qt 4.6.2). Some methods do that, for example:
setScheme(), setAuthority(), setUserInfo(), setUserName(), setPassword(), setHost(), setPort(), setPath(), setEncodedQuery(). I.e. this code works fine:
QList<QUrl> test;
QUrl url;
url.setPath("1");
test.append(url);
qDebug()<<test[0];
url.setPath("2");
test.append(url);
qDebug()<<test[0];
url.setPath("3");
test.append(url);
qDebug()<<test[0] << test[1] << test[2];
Output:
#yiv1579852865 p, #yiv1579852865 li {white-space:pre-wrap;}
QUrl( "1" )
QUrl( "1" )
QUrl( "1" ) QUrl( "2" ) QUrl( "3" )
Causes of this behaviour of the QUrl::setUrl() are unknown for me (may be "value object" pattern). So for add different urls you could use:
QList<QUrl> test;
test.append(QUrl("1"));
test.append(QUrl("2"));
test.append(QUrl("3"));
qDebug()<<test[0] << test[1] << test[2];
Output is:
#yiv1579852865 p, #yiv1579852865 li {white-space:pre-wrap;}
QUrl( "1" ) QUrl( "2" ) QUrl( "3" )
2010/3/26 ice stone <icestone6124 at yahoo.com>
I am trying to figure out a problem involving QList<QUrl>. Here is my code:
QList<QUrl> test;
QUrl url;
url.setUrl("1");
test.append(url);
qDebug()<<test[0];
url.setUrl("2");
test.append(url);
qDebug()<<test[0];
url.setUrl("3");
test.append(url);
qDebug()<<test[0] << test[1] << test[2];
And the output is:
QUrl( "1" )
QUrl( "2" )
QUrl( "3" ) QUrl( "3" ) QUrl( "3" )
My understanding of QList is that it allocates a memory in heap for every inserted item and delete them when they are removed from the list. But the output here seems to point to a single QUrl object for all three items. Anyone can help me to solve this puzzle? Thanks a lot.
Yan
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100326/6cabd8b1/attachment.html
More information about the Qt-interest-old
mailing list