[Qt-interest] Weird compiler error with QString(QChar(value))

Nikos Chantziaras realnc at arcor.de
Wed May 5 21:26:12 CEST 2010


On 05/05/2010 10:14 PM, Gabriel M. Beddingfield wrote:
>
>
> On Wed, 5 May 2010, Nikos Chantziaras wrote:
>
>> 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 got:
>
> error: request for member 'toUtf8' in 's', which is of non-class type
> 'QString ()(QChar)'
>
> I can't explain it, but:
>
> QString s = QString(QChar(unicodevalue));
>
> works. Maybe the compiler things that 's' was function declaration.

Thanks.  That works (QString s = QChar(unicodevalue)).  Indeed, the 
compiler must be mistaking this for a function prototype, given that one 
can put parentheses around the argument identifier.  For example:

   int main( int(argc), char**(argv) )

Tricky, and I didn't know this was possible :P



More information about the Qt-interest-old mailing list