Hi

1.

QmultiHash replace() is only replace first item, I want to replace all values 
when key is matched.

Qt docs : if there are multiple items with the key, the most recently inserted 
item's value is replaced with value.

Who have a better method?

 

2.       so I need to use Qmap<long,Qstring>,

I found qt source code below, so I think Qhash<long,Qstring> is ordered by 
long, am I right?

inline uint qHash(long key) { return qHash(ulong(key)); }

template <class T> inline uint qHash(const T *key)

{

    return qHash(reinterpret_cast<quintptr>(key));

}

 

Thanks

Ken

 

 

________________________________

发件人: Danny Koppel [mailto:[email protected]] 
发送时间: 2013年3月7日 17:39
收件人: 'pengliang(??)'; [email protected]
主题: RE: [Development] [Qt-interest] QMultiHash

 

Hello,

 

I don’t know if I understand you correctly but the QMultiHash class has the 
function replace which does what you describe.

It replaces the value of an existing key or creates a new one if the key 
doesn’t exist yet.

About point 2: the documentation describes it as follows: “When iterating over 
a QMap <qthelp://org.qt-project.qtcore.501/qtcore/qmap.html> , the items are 
always sorted by key. With QHash, the items are arbitrarily ordered.”.

 

Kind regards,

Danny 

 

Van: [email protected] 
[mailto:[email protected]] Namens 
pengliang(??)
Verzonden: donderdag 7 maart 2013 10:25
Aan: [email protected]
Onderwerp: [Development] [Qt-interest] QMultiHash

 

Hi All

 

QMultiHash<Qstring,int>hh;

I need to find some key and change their values.

I found If I use QmutableHashIterator<Qstring,int>it , its 

bool

findNext ( const T & value )

Its parameter is a value, not a key.

So I need to :

While(it.hasNext())

{

It.next();

If(it.key() == ikey)

{

It.setValue(ivalue);
}

}

 

I must to check every item? Who have a better method?

 

2. Qhash:

Some books said Qhash is unorderred?

But I test it.

Qhash<Qstring,int>hh;

I insert some string, and loop the hash by QhashIterator, I found the string is 
orderred.

And I test it Qhash<int,Qstring>, and print key, and found they still orderred.

Why books said it is unorderred?

 

 

Thanks

ken

 

_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to