以例子说明:
#include <QApplication>
#include <QDebug>
#include <QString>
#include <QByteArray> int main(int argc, char *argv[])
{
QApplication a(argc, argv); char abc[];
memset(abc, , sizeof(abc)); QString str("hello world.");
QByteArray arr;
arr = str.toUtf8(); memcpy(abc, arr.data(), strlen(arr.data())); qDebug() << abc;
QString temp = QString::fromUtf8(abc);//将char*转换为QString qDebug() << temp; return a.exec();
}
结果输出:
hello world.
"hello world."