PDA

View Full Version : Error Trying to take out a qlist from a binary file



bmn
17th September 2014, 04:04
QDataStream& operator>>(QDataStream &out, car *&list)
{
QString w,x,y,z;
out>>w;
out>>x;
out>>y;
out>>z;
out>>list->register; //<--- the line who dont run according to the debugger but i dont know why, this is my qlist
list->plate=w;
list->brand=x;
list->mileage=y.toDouble();
list->cylinder_capacity=z.toDouble();
return out;
}

sonulohani
17th September 2014, 05:10
You have to provide the definition of the datatype car, then only we will get to know about the main problem.

bmn
17th September 2014, 06:38
I already do that but I don't why is keeping doing the same error when i tried to read te binary file

stampede
17th September 2014, 08:47
Why are you using a reference to a pointer as second argument to operator >> ? This is how such method looks like most of the time:


QDataStream & operator>>(QDataStream & in, MyClass & obj){
...
return in;
}

What kind of error do you get ? Is your pointer null ?

bmn
17th September 2014, 13:48
It doesn't even run, when my program starts is looking for the file and found it but when i tries do put the qlist inside my instance of qlist don't work
here is the code where I read


QFile read("register.txt");
if(read.exists()){
if (read.open(QIODevice::ReadOnly)){;
QDataStream in(&read);
in.setVersion(QDataStream::Qt_4_6);
in >> cars;
read.close();
}
}
cars is my list in the main (QList<car> cars)

d_stranz
17th September 2014, 19:04
this is my qlist: car *&list

This is not a QList<car>. It isn't even a QList< car * >. It is a reference to a pointer to a "car" instance. So calling "in >> cars" can't possibly call this method if "cars" is actually a QList<car>, because the QDataStream operator you have defined doesn't match the required function signature.

So what does your code really look like? What you have posted isn't complete enough.