[Qt-interest] argv & utf-8 code
Constantin Makshin
cmakshin at gmail.com
Sun Aug 1 22:30:54 CEST 2010
Sorry for intervening, but why not use QCoreApplication::arguments() and let it handle the encoding instead of blindly assuming it's UTF-8? This approach also is more cross-platform because, for example, on Windows 'argv' isn't Unicode at all (unless you use wmain(), but in that you can't pass 'argv' to the Q[Core]Application constructor).
Something like:
QStringList args = qApp->arguments();
for (int i = 1; i < args.count(); ++i)
w.readFileToBuffer(args.at(i));
On Sunday 01 August 2010 06:03:09 1+1=2 wrote:
> w.readFileToBuffer(QString(*(++argv)));
>
> if your are sure that *(++argv) is an utf-8 encoded string,
>
> your should use:
> w.readFileToBuffer(QString::fromUtf8(*(++argv)));
>
> or your can use:
> QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
> w.readFileToBuffer(QString(*(++argv)));
>
> read QString Class Reference to get more infomation.
>
> Debao
>
> On Sun, Aug 1, 2010 at 9:25 AM, Aaron Lewis <aaron.lewis1989 at gmail.com> wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > On 07/31/2010 11:16 PM, 1+1=2 wrote:
> >>> Handler always fire if UTF-8 string appears , it will fail to open ,
> >>
> >> how do you assign the utf-8 string to the QString fName ?
> >
> > I don't know how KDE do it , just put it as a Service Menu ..
> >
> > - --
> > Best Regards,
> > Aaron Lewis - PGP: 0x4A6D32A0
> > FingerPrint EA63 26B2 6C52 72EA A4A5 EB6B BDFE 35B0 4A6D 32A0
> > irc: A4R0NL3WI5 on freenode
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v2.0.16 (GNU/Linux)
> > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> >
> > iEYEARECAAYFAkxUzRkACgkQvf41sEptMqDwswCgi9Sw2iQaJEa5wajl2aLyoYbz
> > /TsAoKejshsEafPpp1EbFWSMkkn36Jol
> > =PDZo
> > -----END PGP SIGNATURE-----
More information about the Qt-interest-old
mailing list