[Qt-interest] Weird compiler error with QString(QChar(value))
Thiago Macieira
thiago at kde.org
Wed May 5 21:27:13 CEST 2010
Em Quarta-feira 5. Maio 2010, às 20.51.00, Nikos Chantziaras escreveu:
> Not sure I understand why this won't compile:
>
> int unicodeValue = func_that_returns_a_unicode_value();
> QString s(QChar(unicodeValue));
> const QByteArray& utf8 = s.toUtf8(); // <-- error happens here
>
> I get:
>
> error: request for member 'toUtf8' in 's', which is of non-class type
> 'QString(QChar)'
>
> I'm confused as hell :P
This is one of the things you just have to learn. This line:
QString s(QChar(unicodeValue));
is not what you think.
You thought you were declaring an object of class QString and calling one of
its constructors with a QChar (which in turn was initialised with an int).
The compiler understood that you were declaring a pointer to a function that
returns QString and takes a QChar as a parameter.
Solution:
QString s = QChar(unicodeValue);
--
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/20100505/48957975/attachment.bin
More information about the Qt-interest-old
mailing list