Convert QString to string
Solved
General and Desktop
-
Hello,
I have a Qstring which contains the path of a folder. I want to convert it into string.QString name = "/Users/macwaves/Desktop/copy to device2" string str= name. toStdString(); std::cout<<str;
OUTPUT: "copy to device2"
I tried everything toUtf8().constData(), toLatin1().data(), toStdString but it produces the same output (Only show "copy to device2" instead of "/Users/macwaves/Desktop/copy to device2").
Any Suggestions?
-
Hi @Punit ,
Try this,
QString name = "/Users/macwaves/Desktop/copy to device2";
std::string text = name.toUtf8().constData();
std::cout<< text;or
QString name = "/Users/macwaves/Desktop/copy to device2";
std::string text = name.toLocal8Bit().constData();
std::cout<< text;In my case,both worked well. I have tested. http://postimg.org/image/rn4sm30sb/