tags:

views:

92

answers:

2

Hello, I am having a QHash. I use the following expression,to check whether a value is there in the QHash::keys() or not. //programme QHash samplehash; QString value = "somevalue"; if(samplehash.contains(value)) // Condition - 1 { //some code }

Sometimes the above conditions matches,sometimes not for the same letters of different case. Can anybody help in this?

A: 

It is case sensitive. The common practice for handling data from multiple sources and comparing it is to convert it all to the same format first, which usually involves making everything lowercase prior to comparison.

This is a common practice, especially on websites for handling logins, or user input in applications to avoid the old 'PEBKAC' situations and make it easier for users.

John T
But,the comparision works sometimes,and sometimes it does not. And i know,the keys in QHash do not change. The value part,can sometimes be lower-case or upper-case.
Ajay
please post your full code
John T
A: 

QHash.contains() is case sensitive as John T mentioned. Without the code there is not much to figure out. You can imagine it doing a == between the keys.

Please do not forget that accessing a non existent element via [] will create an empty entry in the hash, this might be what causes your bug. contains does not insert an entry into the hash, neither does value

Harald Scheirich