[Qt-interest] QList and QUrl problem

Aaron Lewis aaron.lewis1989 at gmail.com
Fri Mar 26 06:19:54 CET 2010


ice stone wrote:
> 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];
>

Shouldn't it be
 
    QList<QUrl> test;
    test << QUrl("1") << QUrl("2") << QUrl("3");
    
     for(int i=0;i<test.size();i++)
         qDebug() << test.at(i);

>  
> 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
>
>
>   

Please use QNetworkAccessManager for any new code , QUrl is deprecated.



-- 
Best Regards,
Aaron Lewis - PGP: 0x4A6D32A0
FingerPrint EA63 26B2 6C52 72EA A4A5 EB6B BDFE 35B0 4A6D 32A0
irc: A4r0n on freenode




More information about the Qt-interest-old mailing list