[Qt-interest] Why do I get a deprecated conversion warning about string to char*?
Thiago Macieira
thiago at kde.org
Tue Aug 10 14:50:27 CEST 2010
Em Terça-feira 10 Agosto 2010, às 14:27:18, Matthias Pospiech escreveu:
> I get this waring everytime I use a char string in the code:
> warning: deprecated conversion from string constant to 'char*'
>
> The code looks like this:
>
> sendCommand("BF");
>
> with this definition
>
> void PI_TranslationStage::sendCommand(QString Command, int const value)
>
> {
>
> QString buffer;
>
> buffer = Command + QString("%1").arg(value);
>
> QByteArray ba = buffer.toLatin1();
>
> char * cbuffer = ba.data();
>
> MMC_sendCommand(cbuffer);
>
> }
>
> How can I get rid of these messages? And why do they appear?
The above code doesn't produce this warning.
The code below however does:
char *foo = "Hello";
Solution: add const:
const char *foo = "Hello";
--
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/20100810/45c703aa/attachment.bin
More information about the Qt-interest-old
mailing list