QT toLocal8Bit奇怪的问题

论坛 期权论坛 脚本     
匿名技术用户   2020-12-31 00:59   59   0

#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

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP