我有一個XML文件,其中包含一些具有名稱和用戶列表的組。在我在構造函數中的代碼,我設置了一個字典此列表:ReadConfig();
QMap中的項目丟失
void AppConfig::ReadConfig(void)
{
...
while(!reader.atEnd())
{
ReadGroups(reader);
if (dictGroups.isEmpty()) qDebug()<<"ReadConfig_isEmpty";
}
...
這就是:
dictGroups= QMap<QString, QList<QString>>() ;
在headerfile作爲
public:
QMap<QString, QList<QString>> dictGroups;
然後我讀了文件,它聲明我的ReadGroups:
void AppConfig::ReadGroups(QXmlStreamReader &reader)
{
dictGroups.clear();
while(!reader.atEnd())
{
reader.readNext();
if (reader.error())
{
...
}
else
{
if (reader.isStartElement())
{
if (reader.name().toString().toLower()=="group"){
ReadGroup(reader);
if (dictGroups.isEmpty()) qDebug()<<"ReadGroups_isEmpty";
}
}
else if (reader.isEndElement())
{
if (reader.name().toString().toLower() == "groups")
{
if(dictGroups.count()<=0){
QList<QString> users= QList<QString>();
users.append(this->GetUsername());
dictGroups.insert("admin", users);
}
return;
}
}
}
}
}
我的問題是,插入在dictGroups而ReadGroups丟失的項目。我得到調試輸出
ReadConfig_isEmpty
但ReadGroups似乎一切正常。 我不知所措,困惑了幾個小時,任何人都可以幫忙找到原因嗎?
你絕對肯定你插入任何東西到'dictGroups'? – thuga
是的:(我的調試打印我插入消息和ReadGroups_isEmpty不會被寫入,並且它不會插入'管理員'用戶,如果字典是空的,因爲在這一步它不是空的 –
很難說什麼沒有[SSCCE](http://sscce.org) – thuga