#include"mainwindow.h"
#include "ui_mainwindow.h"#include<QDebug>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); //测试文件 QString cr2FilePath="abc"; char *fn = cr2FilePath.toLocal8Bit().data(); qDebug()<<fn; //<=========================================这里有时候输出 abc ,有时候输出a qDebug()<<endl; QByteArray text = cr2FilePath.toLocal8Bit(); char * fn2 = new char[text.size() + 1]; strcpy(fn2, text.data()); //<=====================这里又是正确的 qDebug()<<fn2<<endl;}
测试环境:Qt5.2.1 mingw
win8.1 中文 64bit
转载于:https://www.cnblogs.com/stevenlaz/p/4644971.html