QStringList oglądałeś? I metodę QStringList split(QString) QStringa?
Możesz zrobić to tak: wczytujesz cały plik do QStringa, potem na tym rozbijasz go do QStringList metodą split("\n") i masz tablicę (listę) stringów poszczególnych wierszy. Potem na tym (tzn. konkretnych wierszach) split(";") i masz konkretne komórki.
Albo po prostu po staremu: wczytujesz znak po znaku do napotkanego średnika lub znaku końca linii.
W konwersji z pliku testowego na binarny już poradziłem. Zrobiłem to tak:
QFile openFile2("smc.dat");
if (!openFile2.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug()<<"brak pliku";
return 0;
}
QFile file("file.dat");
file.open(QIODevice::WriteOnly);
QTextStream in2(&openFile2);
while (!in2.atEnd())
{
QString line2 = in2.readLine();
if (!(line2.mid(0,3)== "// "))
{
QStringList list2 = line2.split(";");
QDataStream out(&file);
out << QString(list2[0]);
out << list2[1].toDouble();
out << list2[2].toDouble();
}
}
file.close();
A plik binarny odczytuje tak:
QFile file1("file.dat");
file1.open(QIODevice::ReadOnly);
QDataStream in(&file1); // read the data serialized from the file
QString str;
double a1;
double b1;
chciałbym teraz wyświetlić dane. Na razie robię tak:
Serdecznie Pozdrawiam
Grześ
in >> str ; // extract "the answer is" and 42
qDebug()<
in >> a1 ; // extract "the answer is" and 42
qDebug()<
in >> b1 ; // extract "the answer is" and 42
qDebug()<
Niestety wyświetla pierwsze trzy dane:
Mam pytanie jak to zrobić w pętli by wszystkie dane wyświetlały się
Pozdrawiam
Grześ
-- [b]Dodane 04.08.2012 (So) 10:55[/b] --
Witam
Poradziłem sobie
Wystarczyło zrobić tak:
[code] while(!in.atEnd()){ in >> str; qDebug()< in >> a1; qDebug()< in >> b1; qDebug()< }