[Qt-interest] Why do I get a "" key in my map?
Jason H
scorp1us at yahoo.com
Wed Jun 9 17:16:20 CEST 2010
Thanks. With your help I was able to track it down to my curentIndex changed handler that had:
if (_VSNs[_currentSite]!= ui.leVSN->text())
(Its a "dirty" data handler is someone changes the index w/o saving what is in the line edit.)
That subscripting of the _VSNs was creating they key. So when I populate the combo now:
foreach(const QString& site, _VSNs.keys())
{
_currentSite = site;
ui.leVSN->setText(_VSNs.value(site));
ui.cmbSiteNames->addItem(site, _VSNs.value(site));
}
I set the _currentsite and the text before add the item. this causes the slot to not add the item. had you not mentioned that the handler is called when it is emptied, I never would have figured this out.
Thanks!
----- Original Message ----
From: Tony Rietwyk <tony.rietwyk at rightsoft.com.au>
To: qt-interest at trolltech.com
Sent: Wed, June 9, 2010 8:09:51 AM
Subject: Re: [Qt-interest] Why do I get a "" key in my map?
Jason 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
> }
>
> if (_VSNs.keys().count())
> {
> _currentSite= ui.cmbSiteNames->itemText(0);
> ui.cmbSiteNames->setCurrentIndex(0);
> }
> }
>
> Initial data:
> VSNs= (("???????",""))
> cmbSiteNames is a QComboBox. It should have one item of
> "????????" with value of "".
>
> Ending data:
> VSNs= (("", ""), ("???????",""))
>
> Thanks!
Do you have any slots connected to the combobox that update the map? They
will get called with an empty string, or -1 index value, when you empty the
list. This will occur in the while loop after the last item is removed, and
before the while loop tests the condition and stops.
I suggest to add "qDebug() << _VSNs;" between the two loops and confirm what
is in the map there.
Problems like this with slots mean that most of the forms and widgets in my
application have a bool that is set before updating all the child widgets,
which the slots test for and just exit if set. Unfortunately, blockSignals
is too painful to use when there are lots of child widgets.
Hope that helps,
Tony.
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list