[Qt-interest] Segmentation fault while converting from QString to char*
Alexandre Beraud
aberaud at infflux.com
Mon Apr 19 18:14:07 CEST 2010
You have to copy the exact number of bytes pointed to by constData(),
not the arbitrary size of the future container. Depending on the
encoding, the size might not be the number of characters in the QString.
Try ba.size()+1, since the byte at position size() is '\0' and you will
need it to mark the end of your array of characters.
Regards,
Alex
Nikos Chantziaras a écrit :
> Try:
>
> QByteArray ba = qt_file_name.toLatin1();
> strncpy(file_name, ba.constData(), file_name_size);
>
> 'file_name_size' is the size of the 'file_name' target buffer (for
> example "100" if you allocated file_name with "file_name = new char[100]".)
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
--
Alexandre BERAUD
Ingénieur Développement
Infflux - Informatique & Flux
Tel: 01 49 57 92 00 - Fax : 01 49 57 92 01
Mail: aberaud at infflux.com
Visitez notre site : www.infflux.com
More information about the Qt-interest-old
mailing list