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

  #include
#include 
#include 
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();
}

你可能感兴趣的:(QT,平台技术)