简体   繁体   中英

How to use Qmap inside a Qhash?

I have to create a QHash with a map QMap inside it, I have tried to write it as follows:

Declaration:

QMap<int,int>price_vol;
QHash<int,QMap<int,int>>table_maintain;
QList<int>data_list;

Definition:

price_vol.insertMulti(stOrderData->Price,stOrderData->Quantity);
table_maintain.insertMulti(stOrderData->TokenNo,price_vol);
data_list = table_maintain.values();

So I want to know: will I get a QMap for a token number which will map to various values with 'price' as key?

So I want to know: will I get a QMap for a token number which will map to various values with 'price' as key?

Yes, sure.

How can i print all values of tablemaintain?

Just loop through the containers and print their keys and values as you wish; something like this:

foreach (int key, myContainer.keys())
     qDebug() << key << "," << myContainer.value(key);

will the values inside price_vol be sorted by itself?

Sure, that is the main difference between QMap and QHash . QMap will be ordered based on the key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM