Solved Latin char in QListWidget
-
Hi guys.
Can you tell me why my QListWidget don't read polish characters?
Everywhere is that ok but only in QListWidget I have this problem. This is a QT problem or my .txt on PC? This program is reading at the start from this .txt file
-
@naax How do you enter the text? In code?
-
In .txt file?
This is my main "database" so I enter the text manually. And if I run the program my function "load" load this .txt file.
When I'm exporting effects as .txt file I have the same problem
QString fileName = QFileDialog::getSaveFileName( this, tr("Save Document"), QDir::currentPath(), tr("Text files (*.txt)") ); QFile exportDiet(fileName); if (exportDiet.open(QIODevice::WriteOnly | QIODevice::Text)) { //Stream QTextStream stream(&exportDiet); //Print line QTextStream out(&exportDiet); // I tried this but not working QTextStream textStream(&exportDiet); textStream.setCodec("ISO-8859-2"); out << "Imię i Nazwisko: \n"; out << "Dieta: " << ui->showTotalKcals << " kcals\n\n"; out << "Posiłek pierwszy:\n\n"; for (int i = 0; i < ui->mealOneRight->count(); i++) { QListWidgetItem *item = ui->mealOneRight->item(i); out << item->text() <<'\n'; } out << "\nPosiłek drugi:\n\n"; for (int i = 0; i < ui->mealTwoRight->count(); i++) { QListWidgetItem *item = ui->mealTwoRight->item(i); out << item->text() <<'\n'; } out << "\nPosiłek trzeci:\n\n"; for (int i = 0; i < ui->mealThreeRight->count(); i++) { QListWidgetItem *item = ui->mealThreeRight->item(i); out << item->text() <<'\n'; } out << "\nPosiłek czwarty:\n\n"; for (int i = 0; i < ui->mealFourRight->count(); i++) { QListWidgetItem *item = ui->mealFourRight->item(i); out << item->text() <<'\n'; } out << "\nPosiłek piąty:\n\n"; for (int i = 0; i < ui->mealFiveRight->count(); i++) { QListWidgetItem *item = ui->mealFiveRight->item(i); out << item->text() <<'\n'; } exportDiet.close(); }
-
@naax said in Latin char in QListWidget:
out << "Posiłek pierwszy:\n\n";
This will not work, the encoding is wrong. Use a QString and convert it from the correct encoding. Even better use a QTranslator.
-
Ok, ill try to change "out" into QString.
QTranslator I have already but I'm not sure that works well.
int main(int argc, char *argv[]) { QApplication a(argc, argv); QApplication app(argc, argv); QTranslator myappTranslator; myappTranslator.load(QLocale(), QLatin1String("myapp"), QLatin1String("_"), QLatin1String(":/i18n")); app.installTranslator(&myappTranslator); MainWindow w; w.show(); return a.exec(); }
-
This post is deleted!