Hallo,
my program reads an txt file to a QListWidget, but the first row in the txt file is not shown when i open it. All the other rows are shown, except line 1.
Also you can see that there is an empty line after last filled row. in the txt there is no line or space or tab after "9".
void MainWindow::on_btnRead_clicked()
{
QMessageBox::warning(this,
"..",
"keine datei gefunden");
return;
}
while (!text.isNull()) {
text = in.readLine();
ui->listWidget->addItem(text);
}
file.close();
}
void MainWindow::on_btnRead_clicked()
{
QFile file(pfad);
if(!file.open(QFile::ReadOnly | QFile::Text)){
QMessageBox::warning(this,"..","keine datei gefunden");
return;
}
QTextStream in(&file);
QString text = in.readLine();
while (!text.isNull()) {
text = in.readLine();
ui->listWidget->addItem(text);
}
file.close();
}
To copy to clipboard, switch view to plain text mode
txt:
Auswahl_017.png
output in program:
Auswahl_018.png
Added after 1 50 minutes:
Code corrected, now it works:
void MainWindow::on_btnRead_clicked()
{
QMessageBox::warning(this,
"..",
"keine datei gefunden");
return;
}
while (!in.atEnd()) {
text = in.readLine();
ui->listWidget->addItem(text);
}
file.close();
}
void MainWindow::on_btnRead_clicked()
{
QFile file(pfad);
if(!file.open(QFile::ReadOnly | QFile::Text)){
QMessageBox::warning(this,"..","keine datei gefunden");
return;
}
QTextStream in(&file);
QString text;
while (!in.atEnd()) {
text = in.readLine();
ui->listWidget->addItem(text);
}
file.close();
}
To copy to clipboard, switch view to plain text mode
Bookmarks