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

prashant bhutani prashantbhutani2008 at gmail.com
Mon Apr 19 11:40:43 CEST 2010


Hi,
sorry for previous one.
On using statement, *char *cstr = qstr.toStdString.c_str();*
i got *‘qt_file_name.QString::toStdString’ does not have class type*

while on using char *cstr = qstr.toStdString();
i got *cannot convert std::string to char **

Regards,
Prashant

On Mon, Apr 19, 2010 at 3:03 PM, prashant bhutani <
prashantbhutani2008 at gmail.com> wrote:

> 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
>>
>
>


-- 
Prashant Bhutani
Bachelor of Tech.(Comp. Sc.)
4th Semester
Institute of Technology - BHU (IT-BHU)
Varanasi-221005
Mobile: +91-9721505221
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100419/23592000/attachment.html 


More information about the Qt-interest-old mailing list