Std: conversion between wstring and QString

Source: Internet
Author: User
Tags string back

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.