PDA

View Full Version : QDataStream and pointer



stevocz
1st July 2014, 10:47
Hi. how can i send data over QDataStream?

a try this:

QByteArray test;
QtMobility::QGeoMapGroupObject *points = AddToMap();
QDataStream ds(&test, QIODevice::WriteOnly);
ds << points;

but reading not woks

QByteArray packet ....
QtMobility::QGeoMapGroupObject *points = new QtMobility::QGeoMapGroupObject();
QDataStream ds(&packet, QIODevice::ReadOnly);
ds >> points;


i have this error:

error: no match for 'operator>>' in 'ds >> points'

anda_skoa
1st July 2014, 10:57
A pointer just points (hence the name) to the actual data.

If this is a pointer to a list and the list has operators for QDataStream than you can derefernce before streaming.
Otherwise iterate over whatever this is (an array?) and stream each element.
You might want to first stream the length, so you can allocate the necessary structures before reading.

Cheers,
_

stevocz
1st July 2014, 11:28
can you write me example how can i send this data?

anda_skoa
1st July 2014, 12:18
Well, the QGeoMapGroupObject is a QObject derived class, so it can't be easily serialized.

What exactly is your goal?

Cheers,
_

stevocz
1st July 2014, 12:25
in QtMobility::QGeoMapGroupObject i have some routes, pixmap and other things which i can add to map. but this is in plugin. And map is in mainwindow where is connected this plugin. I must send this created QtMobility::QGeoMapGroupObject into mainwindow for adding to map.

anda_skoa
1st July 2014, 14:06
Ah, within the same process.
You don't need to serialize for that.

The plugin host API could have a method that the plugin can call with the pointer or the plugin could emit the object via signal.

Cheers,
_