qt-interest@trolltech.com
[Top] [All Lists]

Re: [Qt-interest] Why do I get a "" key in my map?

Subject: Re: [Qt-interest] Why do I get a "" key in my map?
From: Dan Milburn
Date: Tue, 08 Jun 2010 17:24:30 +0100
Andreas Pakulat wrote:
> On 08.06.10 08:52:12, Jason H wrote:
>> void DlgEditVSN::setVSNs(QMap<QString, QString> VSNs)
>> {
>>     _VSNs = VSNs;
>>     while(ui.cmbSiteNames->count())
>>         ui.cmbSiteNames->removeItem(0);
>>
>>     foreach(const QString& site, _VSNs.keys())
>>     {
>>         ui.cmbSiteNames->addItem(site, _VSNs.value(site)); // THIS LINE 
>> MAKES A NULL KEY IN VSNs
> 
> There's a bit of context missing, in particular you didn't quite formulate
> a clear question. But QMap::value is documented to insert a
> default-constructed value if there is no one yet in the map for the given
> key. So its expected that value inserts into _VSNs if site doesn't exist in
> it yet.
> 
No, calling QMap::value just returns a default-constructed value if it 
doesn't exist in the map.  Using operator[] (the non-const version) will 
silently insert into the map.

Dan
_______________________________________________
Qt-interest mailing list
Qt-interest@xxxxxxxxxxxxx
http://lists.trolltech.com/mailman/listinfo/qt-interest

<Prev in Thread] Current Thread [Next in Thread>