QxSerializeQDataStream_QSharedPointer

Open discussion on QxOrm library

QxSerializeQDataStream_QSharedPointer

Postby Kasuax » Tue Jul 24, 2018 8:01 pm

The following code fails to compile when QxSerialization is turned off. Qt Serialization takes over and does not understand abstract types. I'm not sure how to turn Qt Serialization off too. It looks like it's too closely baked into the framework and needed for ancillary operations.

Code: Select all
template <typename T>
QDataStream & operator<< (QDataStream & stream, const QSharedPointer<T> & t)
{
{
   qint8 iIsNull = 0;
   stream >> iIsNull;
   if (! iIsNull) { t = QSharedPointer<T>(new T()); stream >> (* t); }
   else { t = QSharedPointer<T>(); }
   return stream;
}
Kasuax
 
Posts: 62
Joined: Mon Jun 20, 2016 6:42 pm

Re: QxSerializeQDataStream_QSharedPointer

Postby qxorm » Mon Aug 20, 2018 9:37 am

Hello,

The following code fails to compile when QxSerialization is turned off.

What compilation options have you defined to turn it off ?
I'm not able to reproduce your issue.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: QxSerializeQDataStream_QSharedPointer

Postby Kasuax » Mon Aug 20, 2018 3:47 pm

This was my solution.

Code: Select all
template <typename T>
QDataStream & operator<< (QDataStream & stream, const QSharedPointer<T> & t)
{
   qint8 iIsNull = (t ? 0 : 1);

   if (boost::is_abstract<T>::value)
       iIsNull = 0;

   stream << iIsNull;
   if (t) { stream << (* t); }
   return stream;
}
Kasuax
 
Posts: 62
Joined: Mon Jun 20, 2016 6:42 pm

Re: QxSerializeQDataStream_QSharedPointer

Postby Kasuax » Mon Aug 20, 2018 3:47 pm

It's not a good solution but it moved me a bit further...
Kasuax
 
Posts: 62
Joined: Mon Jun 20, 2016 6:42 pm

Re: QxSerializeQDataStream_QSharedPointer

Postby qxorm » Tue Aug 21, 2018 8:02 am

boost serialization provides more features than Qt serialization.
For abstract classes, boost serialization iterates over all derived classes to check real C++ instance type ==> this is why it works with boost serialization.

With Qt serialization, you can't serialize a pointer to an abstract class for example : you have to cast it to real type before starting the serialization process.
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am


Return to QxOrm - Open discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron