Important: Please read the Qt Code of Conduct -

Latin char in QListWidget

  • Hi guys.

    Can you tell me why my QListWidget don't read polish characters?

    img2.png img1.png

    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

  • Lifetime Qt Champion

    @naax How do you enter the text? In code?

  • @jsulm

    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

    img 4.png

     QString fileName = QFileDialog::getSaveFileName(
                tr("Save Document"),
                tr("Text files (*.txt)") );
        QFile exportDiet(fileName);
        if ( | QIODevice::Text))
            QTextStream stream(&exportDiet);
            //Print line
            QTextStream out(&exportDiet);
            // I tried this but not working
            QTextStream textStream(&exportDiet);
            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';

  • Lifetime Qt Champion

    @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.

  • @Christian-Ehrlicher

    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"));
        MainWindow w;;
        return a.exec();

  • Lifetime Qt Champion

    This post is deleted!

Log in to reply