Convert QString into std::string
I am using a QString in a function named Filename. I want to use it us a global variable, but as a member of std::string library. Is it possible to make such converion? And if yes, then how?
I looked once for it and didn't find.
I changed all the String I used I my project into QString ; they are pretty handy.
Can't you do the same?
If you look at the "FAQs":http://developer.qt.nokia.com/faq/answer/how_can_i_convert_a_qstring_to_char_and_vice_versa you find something about string conversion
You can use the conversion "toStdString":http://doc.qt.nokia.com/4.7/qstring.html#toStdString
Typically I am using the std::string since I have other classes which are relying on stl. QString is in my software only with GUI used. The conversion works without problems.
However, you have to make sure that Qt is configured with -stl in order to have the stl support.
Thanks the conversion toStdString solved my problem
"This":http://developer.qt.nokia.com/faq/answer/how_can_i_convert_a_qstring_to_char_and_vice_versa is the FAQ you need to reference.
I tried toStdString but its giving bad Pointer and program gets crashed.
so i tried this
QString fileName ;
std::string stdFileName = fileName.toLocal8Bit().constData();
and it work fine for me.