[Qt-interest] howto convert QString to char*

Ramesh ramesh.bs at robosoftin.com
Wed Jul 14 06:20:33 CEST 2010


str.toUtf8().data();

 

 

 

-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Matthias Pospiech
Sent: Tuesday, July 13, 2010 9:16 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] howto convert QString to char*

 

I am using the following:

 

    char * toChar(const QString str)

    {

        QByteArray ba = str.toLatin1();

        return  ba.data();

    }

 

the bytearray contains usefull data,

however the value returned by data() is very useless.

Is this because ba is destroyed at the end of toChar?

If so, what would you recommend to make such a conversion?

 

In my code I use this to write

 

QString sendSignal = "1.23 1" // this is set somewhere else

char * str = toChar(sendSignal);

...

// dll functions requiring a char* string...

 

Matthias

_______________________________________________

Qt-interest mailing list

Qt-interest at trolltech.com

http://lists.trolltech.com/mailman/listinfo/qt-interest


-----------------------------------------------
Robosoft Technologies - Come home to Technology

Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100714/a8c81286/attachment.html 


More information about the Qt-interest-old mailing list