![]() |
2010-06-03
, 21:49
|
Posts: 190 |
Thanked: 129 times |
Joined on Mar 2010
@ Bavaria, Germany
|
#2
|
QDataStream &operator<<(QDataStream &out, const Service &service); QDataStream &operator>>(QDataStream &in, Service &service);
QList<Service> services; mystream << services;
QList<Service*> services; mystream << services.size(); foreach(Service* service, services) mystream << *service;
the strange thing is that << seems to work with QList<Service*>!
mystream << *services;
![]() |
2010-06-03
, 22:00
|
Posts: 124 |
Thanked: 10 times |
Joined on Jan 2007
@ Italy
|
#3
|
First, please make the writing function const.
Code:QDataStream &operator<<(QDataStream &out, const Service &service); QDataStream &operator>>(QDataStream &in, Service &service);
error: passing ‘const Service’ as ‘this’ argument of ‘QString Service::getName()’ discards qualifiers
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;
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;
![]() |
2010-06-03
, 22:06
|
Posts: 726 |
Thanked: 345 times |
Joined on Apr 2010
@ Sweden
|
#4
|
what's the matter with this?! i'm still so confused about reference and pointer
![]() |
2010-06-03
, 22:06
|
|
Posts: 1,296 |
Thanked: 1,773 times |
Joined on Aug 2009
@ Budapest, Hungary
|
#5
|
template<typename T> void QSettingsManager::storeBinary(const QString& key, const T& value) { checkSettingsObj(); QByteArray array; QDataStream stream(&array, QIODevice::WriteOnly); stream << value; storeSetting(key, array); }
QList<QString> myList; ... // fill myList with values QSettingsManager::storeBinary<QList<QString> >("settingskey", myList);
The Following User Says Thank You to Venemo For This Useful Post: | ||
![]() |
2010-06-03
, 22:10
|
Posts: 190 |
Thanked: 129 times |
Joined on Mar 2010
@ Bavaria, Germany
|
#6
|
error: passing ‘const Service’ as ‘this’ argument of ‘QString Service::getName()’ discards qualifiers
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?!
Service service; Service* servicePointer = &service; Service& serviceReference = service; Service& serviceReferenceFromPointer = *service;
nice this way, but...should i store manually the list's size before store elements?
what's the matter with this?! i'm still so confused about reference and pointer
The Following User Says Thank You to gri For This Useful Post: | ||
![]() |
2010-06-03
, 22:24
|
Posts: 124 |
Thanked: 10 times |
Joined on Jan 2007
@ Italy
|
#7
|
You can basically serialize a QList<T> if T is serializable. (Meaning: it has a << operator.)
I wrote for myself a class called QSettingsManager for this purpose. You can view the code here and the entire app in this repository.
![]() |
2010-06-03
, 22:32
|
|
Posts: 1,296 |
Thanked: 1,773 times |
Joined on Aug 2009
@ Budapest, Hungary
|
#8
|
is this?!
http://vcs.maemo.org/svn/eve-watcher...ngsmanager.cpp
that's why i said that << and >> work well with "Service*". so T is serializable!
@gri, if i can use non-pointer to do that...i wonder...when a pointer is necessary!?
The Following User Says Thank You to Venemo For This Useful Post: | ||
![]() |
2010-06-03
, 22:46
|
Posts: 726 |
Thanked: 345 times |
Joined on Apr 2010
@ Sweden
|
#9
|
int i = 17; int *pointer_to_int = &i;
*pointer_to_int = 4711;
int **pointer_to_pointer_to_int = &pointer_to_int;
int do_stuff(char *foo, char **error) { ... }
![]() |
2010-06-03
, 22:49
|
Posts: 124 |
Thanked: 10 times |
Joined on Jan 2007
@ Italy
|
#10
|
i'm working with qt nokia sdk and i'm blocked with a strange issue with list serialization!
I've a QList of objects called Service(pointer of Service, QList<Service*>), and i've to store it in a QSetting file using a QDataStream. I've already overloaded << and >> operator for Service objects and they work well.
Now i'm trying to save all the list, but:
here some snap of my code:
load:
QList<Service*> *services;
i hope u can help me