Ich versuche, Zeilen aus einem TXT-Dokument, das Format der txt zu lesen, ist dies:Des Versuch, Zeilen aus Datei in QT zu lesen
Name, Nachname, Alter, Adresse, rut, Telefon
Name, Nachname, Alter, Adresse, rut, Telefon
Name, Nachname, Alter, Adresse, rut, Telefon
Und wenn ich auf den Namen Button „btnVerUsuarios“ werden alle Daten sein in einem TextBrowser auf t sofort angezeigt seine Bestellung:
Name: theName
Nachname: theLastname
Alter: theAge
Adresse: theAddress
RUT: theRut
Telefon: thePhone
Und zwei weitere Male mit allen Daten
Das ist, was ich habe, aber wenn ich versuche, dieses Programm auszuführen, wird ein Fehler und ich habe das Programm schließen:
void MainWindow::on_btnVerUsuarios_clicked()
{
QFile F("datos.txt");
F.open(QIODevice::ReadOnly);
QTextStream leer(&F); //here we have the content of the txt
QStringList parsear; //to parse the specific data from a line
QString nombres; // to save the name
QString apellidos; // to save the lastname
QString edad; // to save the age
QString address; // to save the address
QString rut; // to save the RUT
QString fono; // to save the phone
QString forma = ""; // to save all the data
QString linea = leer.readLine(); // a line
while (!linea.isNull()) {
parsear = linea.split(";"); // parsing
nombres = parsear[0]; // the names
apellidos = parsear[1]; // the lastnames
edad = parsear[2]; // the age
address = parsear[3]; // the address
rut = parsear[4]; // the RUT
fono = parsear[5]; // the phone
linea=leer.readLine(); //to select the next line (or that is what I want)
forma = forma + "Nombres: "+nombres+"\nApellidos: "+apellidos+"\nEdad: "+edad+"\nDirección: "+address+"\nRUT: "+rut+"\nTeléfono: "+fono+"\n\n";
} // The entire data with the required format is ok, now I have to put it in the textBrowser
ui->textBrowser->setText(forma); //putting the entire data int the textBrowser
}
wenn ein anderes einfach es Möglichkeit, dies zu tun, bitte hilf mir dabei.
Entschuldigung für mein schlechtes Englisch und danke.
EDIT
ich sofort alle Daten angezeigt werden versuchte, sorry, wenn ich habe falsch erklärt. Wie auch immer, ich habe meine Frage dank Afflicted's Antwort gelöst.
Möchten Sie alle auf einmal anzeigen, oder gibt der Benutzer einige Informationen ein, die Sie verwenden möchten, um nach bestimmten Dingen zu suchen, mit denen Sie eine bestimmte Zeile mit bestimmten Informationen anzeigen können? – Afflicted
Und welchen Fehler haben Sie? – Apin