There is an implementation of the client's architecture for a game of chess, the logic of which is fully described in the Game class, which contains the fields: Board object (Board) and Piece Class Object List - Piecelist
#ifndef GAME_H #define GAME_H #include <QObject> #include "piece.h" #include "board.h" #include "rook.h" #include "knight.h" #include "bishop.h" #include "queen.h" #include "king.h" #include "pawn.h" #include <QGridLayout> #include <QByteArray> #include <QDataStream> #include <QIODevice> class Game : public QObject { Q_OBJECT public: explicit Game(QObject *parent = 0); QGridLayout* drawBoard(); void start(); void clearStyleSheet(); //QByteArray bytes; friend QDataStream &operator <<(QDataStream &out,Game &game); friend QDataStream &operator >>(QDataStream &out,Game &game); //int k; //friend QDataStream operator<<(&out, const Game &any); QList<Piece*> PieceList; Board* board; signals: public slots: void is_pressed(QPoint coord) ; private: }; #endif // GAME_H Now I want to send using a server implemented as a QTcpServer object of the Game class to a client (another player). I do this: 1) in the Game class I create an overload of QDataStream operators:
QDataStream &operator <<(QDataStream &out,Game &game) { out << game; return out; } 2) Actually call:
Game* game=new Game(); QByteArray bytes; QDataStream out(&bytes,QIODevice::WriteOnly); out<<(*game); And after that the program “successfully” crashes. How to solve this issue. How to transfer a class object over the network using QtcpSocket and QDataStream?