Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Boost::serialization. Serialize in VS. Unserialize in Qt.
Forum Updated to NodeBB v4.3 + New Features

Boost::serialization. Serialize in VS. Unserialize in Qt.

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    za83
    wrote on last edited by
    #1

    I serialize data in application compiled in VS 2012.
    [code]
    class OByteStream
    {
    public:
    explicit OByteStream(std::string &s)
    : _backInsertDevice(s)
    , _stream(_backInsertDevice)
    , _oArchive(_stream)
    {
    }

        void flush()
                   {
                       _stream.flush();
                   }
    
        template<class T>
        OByteStream &operator<<(const T &data)
                   {
                       _oArchive << data;
                       return *this;
                   }
    
    private:
        typedef boost::iostreams::back_insert_device<std::string> BackInsertDevice;
        typedef boost::iostreams::stream<BackInsertDevice> Stream;
        typedef boost::archive::binary_oarchive BinaryOArchive;
    
        BackInsertDevice _backInsertDevice;
        Stream _stream;
        BinaryOArchive _oArchive;
    };
    
    class IByteStream
    {
    public:
        explicit IByteStream(const std::string &s)
            : _basicArraySource(s.data(), s.size())
            , _stream(_basicArraySource)
            , _iArchive(_stream)
        {
        }
    
        template<class T>
        IByteStream &operator>>(T &data)
        {
            _iArchive >> data;
            return *this;
        }
    
    private:
        typedef boost::iostreams::basic_array_source<char> BasicArraySource;
        typedef boost::iostreams::stream<BasicArraySource> Stream;
        typedef boost::archive::binary_iarchive BinaryIArchive;
    
        BasicArraySource _basicArraySource;
        Stream _stream;
        BinaryIArchive _iArchive;
    };
    

    [/code]

    [code]

            template<class Archive>
            void serialize(Archive & ar, Data & data, const unsigned int version)
            {
                    ar & data.a;
                    ar & data.b;
                    ar & data.c;
            }
     
        std::string serial;
           
        OByteStream obs(serial);
        obs << data;
        obs.flush();
     
        IByteStream ibs(serial);
        ibs >> data;
    

    [/code]

    Then I send it to application compiled in Qt (msvc 2012).

    And when some 2d vectors unserializing an exception happens.

    [code]
    if(scount != s)
    boost::serialization::throw_exception(
    archive_exception(archive_exception::input_stream_error)
    );
    [/code]

    I tried to use all Struct Member Alignments in VS. It did not help. In QtCreator I did not find such option.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved