[Qt-interest] argv & utf-8 code
Thiago Macieira
thiago at kde.org
Sat Jul 31 17:21:22 CEST 2010
On Saturday 31. July 2010 11.55.16 Aaron Lewis wrote:
> Hi,
> In main() , i've got a simple class w , which has a function
> readFileToBuffer(QString fName).
>
> Well it's like this:
>
> In main():
> if(argc > 2){
> w.readFileToBuffer(QString(*(++argv)));
> }
>
> And in class codecs:
>
> void codecs::readFileToBuffer(QString fileName)
> {
> QFile file(fileName);
> if (!file.open(QFile::ReadOnly)) {
> // Hanlder, Popup a message , telling file can't be opened
> }
> }
>
> Handler always fire if UTF-8 string appears , it will fail to open ,
> it's problems with non-ascii strings , anyone could help ?
There are two problems with the code you pasted above:
1) There's no QCoreApplication
2) You're converting from a char* to QString via fromAscii() (the implicit
constructor), which is *documented* to use Latin1, not UTF-8.
So, please address those two things, by adding the QCoreApplication to your
main function (or telling us it's there) and by compiling your code with
QT_NO_CAST_TO_ASCII and QT_NO_CAST_FROM_ASCII. Those two macros will turn into
errors any use of the implicit conversion to and from char*, which are not
what you want.
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
Senior Product Manager - Nokia, Qt Development Frameworks
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100731/8323c255/attachment.bin
More information about the Qt-interest-old
mailing list