我对 QMap 有疑问。每个键都有许多值。这个想法是用它的唯一键显示所有值。要使用 QtGui 应用程序遍历此地图,我有 TextEdit(名称:t2)。代码在按钮内,如下所示:
void MainWindow::on_push2_clicked()
{
QMap<int, QStringList> myMaps;
myMaps[1].append("Autodesk Maya 2014");
myMaps[1].append("Autodesk Inventor 2014");
myMaps[1].append("Autodesk Alias 2014");
myMaps[1].append("Autodesk 3ds Max 2014");
myMaps[1].append("Autodesk Softimage 2014");
myMaps[2].append("Adobe Photoshop CS6");
myMaps[2].append("Adobe Illustrator CS6");
myMaps[2].append("Adobe InDesign CS6");
myMaps[1].append("Autodesk AutoCAD 2014");
QStringList stsl; // the StringList which contains all values
QMap<int, QStringList>::iterator it;
for (it=myMaps.begin(); it!=myMaps.end(); ++it) {
QString qsi=QString::number(it.key());
QString qs=it.value().join(" - ");
stsl << "<span style='color:#FF1000;font-weight:bold;'>"+qsi + " : </span>"+ qs;
}
QString st4=stsl.join("<br/>"); //With setHtml
ui->t2->setHtml(st4);
}
}
// 输出: 1:Autodesk Maya 2014 - Autodesk Inventor 2014 - Autodesk Alias 2014 - Autodesk 3ds Max 2014 - Autodesk Softimage 2014 - Autodesk AutoCAD 2014 - Lightwave 12 2:Adobe Photoshop CS6 - Adobe Illustrator CS6 - Adobe InDesign CS6。
// 我想做的输出: 1:Autodesk Maya 2014 1:Autodesk Inventor 2014 1:Autodesk Alias 2014 1:Autodesk 3ds Max 2014 1:Autodesk Softimage 2014 1:Autodesk AutoCAD 2014 2:Adobe Photoshop CS6 2:Adobe Illustrator CS6 2:Adobe InDesign CS6