PDA

View Full Version : Encoding a QString to No.?



vishal.chauhan
30th August 2007, 13:44
Hi All,

I m using QT 4.1.5 on my MAC.
I have a QString to which I want to Encode to Numbers and then want to write it to a file.

So if anyone know how I can do it then plz help me.

Thanks.

Rayven
30th August 2007, 13:51
Hi All,

I m using QT 4.1.5 on my MAC.
I have a QString to which I want to Encode to Numbers and then want to write it to a file.

So if anyone know how I can do it then plz help me.

Thanks.

For QStrings there is a toInt( ) (or toDouble( ), etc) function that will convert the string to the appropriate number.
http://doc.trolltech.com/4.1/qstring.html#toInt

To convert a number into a string, there is a static function QString::number( int num, int base ) http://doc.trolltech.com/4.1/qstring.html#number that returns a QString.

vishal.chauhan
30th August 2007, 13:58
Thanks for Reply.

But I want Encoding of QString to number as

If I have a QString like QT CENTER then it will encode it to something like 275161967.

wysota
30th August 2007, 14:25
What kind of encoding would you like to use?

vishal.chauhan
30th August 2007, 14:49
Any type of encoding.

It should be simple or complex.

marcel
30th August 2007, 15:09
How did you compute that number for QT CENTRE?
For a given char you can get its unicode code with QChar::unicode();

Maybe you can use that unique value to build a number from a string.

Regards

Wizard
30th August 2007, 19:08
Thanks for Reply.

But I want Encoding of QString to number as

If I have a QString like QT CENTER then it will encode it to something like 275161967.

Try to search in the Internet about hashing. If you want to encode it into one integer, try CRC32 algorithm. Remenber, that hashing is irreversible...