我有一个结构:
typedef struct
{
Qt::Key qKey;
QString strFormType;
} KeyPair;
现在我初始化 KeyPair 实例,以便我可以将它用于我的自动化测试应用程序。
KeyPair gDial[] =
{
{ Qt::Key_1 , "MyForm" },
{ Qt::Key_1 , "SubForm" },
{ Qt::Key_Escape, "DesktopForm" }
};
KeyPair gIP[] =
{
{ Qt::Key_1 , "MyForm" },
{ Qt::Key_2 , "Dialog" },
{ Qt::Key_2 , "Dialog" },
{ Qt::Key_Escape, "DesktopForm" }
};
....
and like 100 more instantiations....
目前,我调用了一个使用这些 KeyPairs 的函数。
qDebug() << "Testing Test Menu";
pressKeyPairs( gDial);
qDebug() << "Testing Browse Menu";
pressKeyPairs( gIP);
....
and more calls like this for the rest...
我想将所有这些 KeyPair 实例放在一个 MAP 中,这样我就不必调用 pressKeyPairs() 和 qDebug() 一百次了......我是使用 MAPS 的新手......所以我尝试了:
map<string,KeyPair> mMasterList;
map<string,KeyPair>::iterator it;
mMasterList.insert( pair<string, KeyPair>("Testing Test Menu", *gDial) ); //which I know is wrong, but how?
mMasterList.insert( pair<string, KeyPair>("Testing IP Menu", *gIP) );
mMasterList.insert( pair<string, KeyPair>("IP Menu2", *gIP2) );
....
for ( it=mMasterList.begin() ; it != mMasterList.end(); it++ )
{
qDebug() << (*it).first << endl;
pressKeyPairs((*it).second);
// I don't know how to access .second ... this causes a compiler error
}
编辑: pressKeyPairs 声明为:
template <size_t nNumOfElements> void pressKeyPairs(KeyPair (&keys)[nNumOfElements]);
此代码块不起作用... :( 有人可以告诉我如何正确地将这些 KeyPairs 放入 Map 中吗?