QMap 在获取不到 value 时,默认值为 0

来源:互联网 发布:程序员的压力大 编辑:程序博客网 时间:2024/06/09 11:08
 #include <QApplication>
#include <QtCore/QtCore>
#include <QMap>
enum UnitsType{SPS,DPS,SPC,DPC,INS,MV,CMV,SPG,ING,ASG,STG};
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QMap<QString,int> itemTypeMap;
    itemTypeMap["SPS"] = SPS;
    itemTypeMap["DPS"] = DPS;
    itemTypeMap["SPC"] = SPC;
    itemTypeMap["DPC"] = DPC;
    itemTypeMap["INS"] = INS;
    itemTypeMap["MV"] = MV;
    itemTypeMap["CMV"] = CMV;
    itemTypeMap["SPG"] = SPG;
    itemTypeMap["ING"] = ING;
    itemTypeMap["ASG"] = ASG;
    itemTypeMap["STG"] = STG;
    qDebug()<<itemTypeMap.value("SPS");   // 输出:0
    qDebug()<<itemTypeMap.value("aadfa"); //输出:0
    return app.exec();
}
原创粉丝点击