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. QDataStream serialze & deserialize 'myclass' pointer
Forum Updated to NodeBB v4.3 + New Features

QDataStream serialze & deserialize 'myclass' pointer

Scheduled Pinned Locked Moved Solved General and Desktop
24 Posts 4 Posters 9.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.
  • Taz742T Taz742

    @kshegunov @VRonin
    How to handle QDataStream to my classes, this are stored in one 'header' file.
    It's uncomfortable for me because I have many issues.
    I learnt to my classes QDataStream >> and << operators.

    For Example:

    #ifndef POINT3D_H
    #define POINT3D_H
    
    #include "QObject"
    #include "QDataStream"
    
    class Point3D
    {
    public:
        Point3D();
        int x;
        int y;
        int z;
    
        Point3D(int _x, int _y, int _z) {
            this->x = _x;
            this->y = _y;
            this->z = _z;
        }
    
        friend QDataStream & operator << (QDataStream &stream, const Point3D &obj);
        friend QDataStream & operator >> (QDataStream &stream, Point3D &obj);
    };
    
    Q_DECLARE_TYPEINFO(Point3D, Q_MOVABLE_TYPE);
    
    #endif // POINT3D_H
    
    #include "point3d.h"
    
    Point3D::Point3D()
    {
    
    }
    
    QDataStream & operator << (QDataStream &stream, const Point3D &obj) {
        stream << static_cast<qint32>(obj.x) << static_cast<qint32>(obj.y) << static_cast<qint32>(obj.z);
        return stream;
    }
    
    QDataStream & operator >> (QDataStream &stream, Point3D &obj) {
        qint32 tempint;
        stream >> tempint; obj.x = static_cast<int>(tempint);
        stream >> tempint; obj.y = static_cast<int>(tempint);
        stream >> tempint; obj.z = static_cast<int>(tempint);
    
        return stream;
    }
    

    I want to be sure that this will work from anywhere. Can you confirm it?

    kshegunovK Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by
    #21

    @Taz742 said in QDataStream serialze & deserialize 'myclass' pointer:

    I want to be sure that this will work from anywhere. Can you confirm it?

    I don't understand the question, could you elaborate.

    Read and abide by the Qt Code of Conduct

    Taz742T 1 Reply Last reply
    0
    • kshegunovK kshegunov

      @Taz742 said in QDataStream serialze & deserialize 'myclass' pointer:

      I want to be sure that this will work from anywhere. Can you confirm it?

      I don't understand the question, could you elaborate.

      Taz742T Offline
      Taz742T Offline
      Taz742
      wrote on last edited by
      #22

      @kshegunov said in QDataStream serialze & deserialize 'myclass' pointer:

      I don't understand the question, could you elaborate.

      I have class Point3D which know how to behave when datastream requires input(<<) or output(>>) operators.
      I want to know if it will works from anyclasses, for example: from mainwindows and etc..

      Do what you want.

      kshegunovK 1 Reply Last reply
      0
      • Taz742T Taz742

        @kshegunov said in QDataStream serialze & deserialize 'myclass' pointer:

        I don't understand the question, could you elaborate.

        I have class Point3D which know how to behave when datastream requires input(<<) or output(>>) operators.
        I want to know if it will works from anyclasses, for example: from mainwindows and etc..

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #23

        Why wouldn't it? As long as the functions have declarations at the point of usage it's the linker's problem to tie it all together ... it's the singular purpose for which the linker exists actually.

        Read and abide by the Qt Code of Conduct

        Taz742T 1 Reply Last reply
        3
        • kshegunovK kshegunov

          Why wouldn't it? As long as the functions have declarations at the point of usage it's the linker's problem to tie it all together ... it's the singular purpose for which the linker exists actually.

          Taz742T Offline
          Taz742T Offline
          Taz742
          wrote on last edited by
          #24

          @kshegunov Now I'm sure. thanks.

          Do what you want.

          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