I had this section of code wording a few days ago, now having fixed other things it has stopped! The screen has two inverted commas " and no output.
The output file lines look like this.
1, Lata Becker, 29 Atterbury Road, 1110, Port Elizabeth, 074 3546902
2,CD Viljoen, 1 Kelvin, 0010, Victoria, 022 4699087
1, Lata Becker, 29 Atterbury Road, 1110, Port Elizabeth, 074 3546902
2,CD Viljoen, 1 Kelvin, 0010, Victoria, 022 4699087
To copy to clipboard, switch view to plain text mode
I create the file from
QString result
= QString::number(category,
10) + ", " + firstName
+ " " + lastName + ", " + streetAddress + ", " + zipCode + ", " + city + ", " +
phoneNumber;
return result;
}
QString Contact::toString()const {
QString result = QString::number(category,10) + ", " + firstName + " " +
lastName + ", " + streetAddress + ", " + zipCode + ", " + city + ", " +
phoneNumber;
return result;
}
To copy to clipboard, switch view to plain text mode
The \n is added by the calling function. There are no start or end characters in the file.
The writer appears to write correctly - this is the reader that crashes...
void ContactListReader::read(ContactList &mylist)
{
while(!infile.atEnd()) {
if(line != "\n") {
QString fn
= (list.
at(1).
split(" ")).
at(0);
QString ln
= (list.
at(1).
split(" ")).
at(1);
mylist.add(Contact((list.at(0)).toInt(),fn,ln,list.at(2),list.at(3),list.at(4),list.at(5)));
}
}
infile.close();
}
void ContactListReader::read(ContactList &mylist)
{
QFile infile(fn);
infile.open(QIODevice::ReadOnly);
QTextStream out(&infile);
while(!infile.atEnd()) {
QString line = infile.readLine();
if(line != "\n") {
QStringList list = line.split(", ");
QString fn = (list.at(1).split(" ")).at(0);
QString ln = (list.at(1).split(" ")).at(1);
mylist.add(Contact((list.at(0)).toInt(),fn,ln,list.at(2),list.at(3),list.at(4),list.at(5)));
}
}
infile.close();
}
To copy to clipboard, switch view to plain text mode
Should I be looking beyond these items for a solution? An included file etc?
Bookmarks