简体   繁体   English

如何在Qhash中使用Qmap?

[英]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: 我必须在其中创建一个带有地图QMap的QHash,我试着按如下方式编写它:

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? 所以我想知道:我是否会得到一个代号的QMap ,它会映射到以'price'为关键的各种值?

So I want to know: will I get a QMap for a token number which will map to various values with 'price' as key? 所以我想知道:我是否会得到一个代号的QMap,它会映射到以'price'为关键的各种值?

Yes, sure. 是的,当然。

How can i print all values of tablemaintain? 如何打印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? price_vol里面的值会自行排序吗?

Sure, that is the main difference between QMap and QHash . 当然,这是QMapQHash之间的主要区别。 QMap will be ordered based on the key. QMap将根据密钥进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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