Recently, I was working on a project where someone else's program was used, and the interface of this program gave std: wstring type, while processing the string, QString in QT is much more powerful than wstring, so the conversion between these two types of strings is required.
First, we will introduce converting std: wstring to QString.
The QString function is used here.
QString qStr;qStr= QString::fromStdWString(wStr);
Here, qStr is the converted string, and wStr is the string used before conversion.
After the conversion, perform column processing on qStr, for example:
qStr.replace("/", "\\\\");
This process means to replace all/in the string qStr with \. wstring does not have such a function.
After processing, we need to re-convert the QString type string back to wstring.
Functions in QString,
wStr = qStr.toStdWString()
The following is a complete example.
std::wstring wStr = L"C:\windows\system32\hao123\tianCai\";QString qStr = QString::fromStdWString(wStr);qStr.replace("/","\\\\");wStr = qStr.toStdWString();
The final result should be known as "C: // windows // system32 // hao123 // tianCai //" stored in wStr //"
This article from the "selling cute programmers" blog, please be sure to keep this source http://7677869.blog.51cto.com/7667869/1281413