[Qt-interest] Qt code compiles fine on mscv9.0 but failed with gcc
Bruno Colombet
Bruno.Colombet at univmed.fr
Tue Jan 25 14:44:06 CET 2011
Le 25/01/2011 14:35, Thiago Macieira a écrit :
> Em terça-feira, 25 de janeiro de 2011, às 14:24:59, Bruno Colombet escreveu:
>> Hello everybody,
>>
>> I'm developping a Qt application for several months now and my main IDE
>> is Visual Studio 2008 on Windows.
>> By the way, I must assure my application compiles on Linux and Mac OS X.
>>
>> I get used to modify part of my code to make sure gcc will compile it
>> but I wonder if there is a clean way to solve my problem.
>> Here is an example :
>>
>> Class myclass
>> {
>> public:
>> void setName(QString& name);
>> }
>>
>>
>> myclass mc;
>>
>> mc.setName(QString("test");<=== compiles fine with MSCV
> MSVC is wrong. The code is not valid.
>
> QString("test") produces a temporary QString object, which must be an rvalue.
> So you can't assign it to a QString&, which is a non-const reference (takes
> an lvalue).
>
>> got errors with gcc : no matching function for call
>> 'myclass::setName(QString)' candidates are : void myclass::setName(QString&)
>>
>> And a more complex problem in an other part of the code I have a methode
>> like this :
>>
>> - void addCustomChannel(Channel *channel, QString& after = QString("LAST"));
> Also wrong.
>
> Please add the "const" and everything will compile.
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
Thanks for help. I thought MSVC compiler was implicitly doing the
correct job. I'll be on my guard now, thanks again.
--
Bruno Colombet
*INSERM UMR 751* - Epilepsie et Cognition
Faculté de Médecine
27 Bd Jean Moulin
13385 Marseille cedex 05
+33 4 91 38 55 40
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110125/e469f0f8/attachment.html
More information about the Qt-interest-old
mailing list