View Single Post
Posts: 124 | Thanked: 10 times | Joined on Jan 2007 @ Italy
#3
Originally Posted by gri View Post
First, please make the writing function const.
Code:
QDataStream &operator<<(QDataStream &out,  const Service &service);
QDataStream &operator>>(QDataStream &in, Service &service);
mmm why do that?! btw if i make it const i've this:
Code:
 error: passing ‘const Service’ as ‘this’ argument of ‘QString Service::getName()’ discards qualifiers
To solve i've to add const in getName()(and other get metods), like:
getName() const { return name;}



Originally Posted by gri View Post
The second is, you can only use non-pointer types of Service when exporting the whole QList to a QDataStream. The following would work:
Code:
QList<Service> services;
mystream << services;
that's would be good, but i've to pass these pointers to other class in order to edit them, so i think i can't use non-pointer...am i right?!



Originally Posted by gri View Post
If you can't change to non-pointer type, you will have to iterate through the list at your own.
Code:
QList<Service*> services;
mystream << services.size();
foreach(Service* service, services)
  mystream << *service;
nice this way, but...should i store manually the list's size before store elements?



Originally Posted by gri View Post
Edit: Also please stay away from creating QList<>s on the heap
what's the matter with this?! i'm still so confused about reference and pointer

Last edited by saxen; 2010-06-03 at 22:02.