QT6中的重音和特殊字符是否破裂?

发布于 2025-01-27 20:20:22 字数 895 浏览 1 评论 0原文

我有一个QT程序,可以从CSV文件中读取并将信息保存到数据库中。 直到我尝试从QT 5.15.2更新到QT 6.3之前,没有问题。现在,当我从文件中阅读时,所有口音都会转换为问号。

我尝试使用几乎所有方法来明确解释QTEXTSTREAM或将QString文本转换为UTF-8或Unicode,它们都无法正常工作。这是QT 6中的一个已知问题(因为重音在QT 5.15.2中完美效果)吗?

提前致谢。

按照要求,这是读取CSV文件的片段:

QFile file(path);
file.open(QIODevice::ReadOnly | QIODevice::Text);

QTextStream in(&file);
while (in.readLineInto(&line)){
   QStringList separatedLine = line.split("\t");
   qDebug() << separatedLine;
   //do things and save data in database
}

我遇到的问题是,如果我使用QT5.15.2编译,但在QT6.3.0中不使用它,则可以很好地工作。读取完全相同的.csv文件以下是删除:

//原始行
34111514 TARJETACOMUNICACIónTMB-251 TMB251

// QT 5.15.2 QDEBUG输出
Qlist(“ 34111514”,“ TarjetacomunicaciónTMB-251”,“ TMB251”)

// QT 6.3 QDEBUG输出
Qlist(“ 34111514”,“ Tarjeta comunicaci?n tmb-251”,“ TMB251”)

我非常怀疑CSV文件格式是否有问题,因为它在较旧的QT中可以正常工作。

I've got a Qt program that reads from csv files and saves the info into a database.
There was no problem until i tried to update from Qt 5.15.2 to Qt 6.3. Now, when I read from the files, all accents are converted to a question mark.

I've tried using pretty much every way to explicitly interpret a QTextStream or convert a QString text to Utf-8 or Unicode in general and they all failed to work. Is this a known issue in Qt 6 (because accents worked perfectly in Qt 5.15.2)?

Thanks in advance.

As requested here's the fragment that reads the csv files:

QFile file(path);
file.open(QIODevice::ReadOnly | QIODevice::Text);

QTextStream in(&file);
while (in.readLineInto(&line)){
   QStringList separatedLine = line.split("\t");
   qDebug() << separatedLine;
   //do things and save data in database
}

The issue I have is that this works perfectly if I compile it with Qt5.15.2 but not in Qt6.3.0. Reading the exact same .csv file the following is debbuged:

//Original line
34111514 TARJETA COMUNICACIÓN TMB-251 TMB251

//Qt 5.15.2 qDebug outputs
QList("34111514", "TARJETA COMUNICACIÓN TMB-251", "TMB251")

//Qt 6.3 qDebug outputs
QList("34111514", "TARJETA COMUNICACI?N TMB-251", "TMB251")

I highly doubt it's a problem with the csv file formatting because it works fine in older Qt.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃繁缕 2025-02-03 20:20:23

好的,经过几天的研究并尝试了现在的工作。我无法复制该问题,但是当我使用libreoffice calc来保存编码为UTF-8的CSV或通过电子邮件发送该文件时,一定发生了一些事情。
我想编码可能以某种方式变成或破坏了某些原因,出于某种原因,QT5.15.2可以解释,但是QT6.3不能。
我通过使用记事本++再次将文件编码为UTF-8来解决问题。

Okay so after a couple more days of research and trying things it now works. I cannot reproduce the issue but something must have had happened when I used LibreOffice Calc to save the csv encoded as UTF-8 or when I sent that file by email.
I suppose the encoding might have gotten in some way changed or corrupted into something that, for some reason, Qt5.15.2 could interpret but Qt6.3 couldn't.
I fixed the issue by using Notepad++ to encode the file as UTF-8 again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文