[Qt-interest] Segmentation fault while converting from QString to char*

prashant bhutani prashantbhutani2008 at gmail.com
Mon Apr 19 09:56:34 CEST 2010


Hi everyone,

I am making a program which fetch a file from directory using *
getOpenFileName* and it returns the path as a *QString*.
Now I have to convert the path in *char** which i am doing using
         *QByteArray ba = qt_file_name.toLatin1();    *//qt_file_name is
path of file in Qstring
*         const char* temp = ba.data();                        *
*         strcpy(file_name,temp);                                 *//
file_name is in char*

Now the code is causing segmentation fault in my program as it runs fine
when these statements are made comments.
Can anyone please tell the reason for segmentation fault and how to remove
it?

I have also used *toLatin1* ,* toAscii* to convert QSrting to char* but all
cause same segmentation fault.

Regards,
Prashant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100419/5c90383e/attachment.html 


More information about the Qt-interest-old mailing list