相关疑难解决方法(0)

QChar到wchar_t

我需要将QChar转换为wchar_t

我尝试过以下方法:

#include <cstdlib>
#include <QtGui/QApplication>
#include <iostream>

using namespace std;

int main(int argc, char** argv) {

    QString mystring = "Hello World\n";
    wchar_t myArray[mystring.size()];

    for (int x=0; x<mystring.size(); x++)
    {
        myArray[x] = mystring.at(x).toLatin1();
        cout << mystring.at(x).toLatin1(); // checks the char at index x (fine)
    }

    cout << "myArray : " << myArray << "\n"; // doesn't give me correct value
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

哦,在有人建议使用.toWCharArray(wchar_t*array)函数之前,我已经尝试过了,它基本上做了与上面相同的事情,并没有按照它应该传输字符.

如果你不相信我,下面是代码:

#include <cstdlib>
#include <QtGui/QApplication>
#include <iostream>

using namespace std;

int main(int argc, char** argv) { …
Run Code Online (Sandbox Code Playgroud)

c++ unicode qstring qt wchar-t

6
推荐指数
1
解决办法
5095
查看次数

标签 统计

c++ ×1

qstring ×1

qt ×1

unicode ×1

wchar-t ×1