[Qt-interest] Qt code compiles fine on mscv9.0 but failed with gcc

Thiago Macieira thiago at kde.org
Tue Jan 25 14:35:25 CET 2011


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.

-- 
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/20110125/b0233f05/attachment.bin 


More information about the Qt-interest-old mailing list