[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: How to conver a QString value to  int?
From:       Dirk Mueller <mueller () kde ! org>
Date:       2001-11-03 12:15:48
[Download RAW message or body]

On Sam, 03 Nov 2001, Force Ding wrote:

> Hi:
>   I want to cover a QString to char?

you can't actually. thats because QString stores the information of at least 
2 chars, so it will become really difficult to put the same amount of 
information in a single char. 

> When I use code like this 
> QString CBase64::m_sBase64Alphabet =
> ( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" );

you shouldn't use static QString members. global constructors for non-POD 
types are dangerous on some (broken) platforms, like Solaris. If you care 
about portability, don't do this. 

> int i=(int)m_sBase64Alphabet[i]
> my kdevelop say "cannot convert `QCharRef' to `int' in assignment"
> Is QString not base on char?

No. Also, you shouldn't use "i" in an "int i" initialisation. While the 
compiler doesn't complain about it, it for sure won't work the way you 
expected it. 

What you're probably looking for is 

  if(testqchar.isLetterOrNumber() || testqchar == '+' || testqchar == '/')
   ..

which is equivalent to above. 

> And if I encode a MIME file, QString and QCString which is better to use 
> encode base64.

Better to use is the ready-to-use functionality in kdecore (kmdcodec.h)


Dirk
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic