Hi,
my program has to work on Windows and Android.
When I want to display files in a folder, I have encoding problems, as Android apparently uses utf8 for its file system. This is what I do:
ui->label->setText("Hallo Ä Ö Ü ä ö ü ß .,;*+");
for (int i= 0;i<files.count();i++)
{
ui->treeWidget->addTopLevelItem(item);
}
ui->label->setText("Hallo Ä Ö Ü ä ö ü ß .,;*+");
QStringList files=dir.entryList(QStringList()<<"*.*");
for (int i= 0;i<files.count();i++)
{
QTreeWidgetItem* item=new QTreeWidgetItem(QStringList()<<files.at(i));
ui->treeWidget->addTopLevelItem(item);
}
To copy to clipboard, switch view to plain text mode
The label->setText stuff is shown correctly, so this is not a display thing. The treeWidget looks like this
android.jpg (Android)
instead of this
windows.jpg (Windows).
So the umlauts are borked.
I've tried setting the default locale to german and english, but this didn't help:
// QLocale::setDefault(englishLocale);
QLocale germanLocale(QLocale::German,QLocale::Germany) ;
QLocale englishLocale(QLocale::English, QLocale::UnitedStates);
QLocale::setDefault(germanLocale);
// QLocale::setDefault(englishLocale);
To copy to clipboard, switch view to plain text mode
Furthermore I've tried getting the entryInfoList, then decoding the fileName. But since QFileInfo::fileName() returns a String, I feel like chasing my own tail here:
QFileInfoList infos
=dir.
entryInfoList(QStringList()<<
"*.*");
for (int i=0; i<infos.count();i++)
{
QString fileName
= QFile::decodeName(inf.
fileName().
toUtf8());
ui->treeWidget->addTopLevelItem(item);
}
QFileInfoList infos=dir.entryInfoList(QStringList()<<"*.*");
for (int i=0; i<infos.count();i++)
{
QFileInfo inf=infos.at(i);
QString fileName= QFile::decodeName(inf.fileName().toUtf8());
QTreeWidgetItem* item=new QTreeWidgetItem(QStringList()<<fileName);
ui->treeWidget->addTopLevelItem(item);
}
To copy to clipboard, switch view to plain text mode
Needless to say that it also didn't work.
I'm at my (small) wit's end.
Bookmarks