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

prashant bhutani prashantbhutani2008 at gmail.com
Mon Apr 19 11:33:31 CEST 2010


Hi,

On using this statement,
char *cstr = qstr.toStdString.c_str();
I got
cannot convert std::string to char *

any other method please
Regards,
Prashant


On Mon, Apr 19, 2010 at 1:32 PM, Iwan Budi Kusnanto <iwanbk at gmail.com>wrote:

> QString qstr = ....
> char *cstr = qstr.toStdString.c_str();
>
> On 4/19/10, prashant bhutani <prashantbhutani2008 at gmail.com> wrote:
> > 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
> >
> > _______________________________________________
> >  Qt-interest mailing list
> >  Qt-interest at trolltech.com
> >  http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> >
>
>
> --
> Iwan Budi Kusnanto
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100419/e5ecc1a0/attachment.html 


More information about the Qt-interest-old mailing list