Qt Serialization no match for operator << operand types are 'QDataStream'












0















I have a problem during serialization with a simple Managed Structure.



My Class Header



class MappySaver
{

public:
MappySaver();

//structure
struct Tile
{
public:
int ID;
int x,y,w,h;
QRect rect;
};

QList<Tile> Tiles;
QObject t;
Tile tile;

};

QDataStream& operator << (QDataStream& s, const MappySaver::Tile& tile);
QDataStream& operator >> (QDataStream& s, MappySaver::Tile& tile);


#endif // MAPPYSAVER_H


and source cpp



   QDataStream &operator<<(QDataStream &s, const MappySaver::Tile& tile)
{
s << tile;
return s;
}


When I try to compile this, I get this error:




error: no match for 'operator<<' (operand types are 'QDataStream' and 'const MappySaver::Tile')




template <typename T> //QDataStream.h
QDataStream& operator<<(QDataStream& s, const QList<T>& l)
{
s << quint32(l.size());
for (int i = 0; i < l.size(); ++i)
s << l.at(i);
return s;
}


I use this class to serialize a list.
On the main form, I have a widget with the same data.



And I use this method for try to serialize.



QString filename = QFileDialog::getSaveFileName(this,
tr("Seleziona il file da salvare"),"",
tr("File Mappa (*.mp2d)"));

MappySaver::Tile t;
MappySaver m;


for(int i = 0; i < ui->maps->Tiles.count(); i++)
{
t.ID = ui->maps->Tiles[i].ID;
t.h = ui->maps->Tiles[i].h;
t.rect = ui->maps->Tiles[i].rect;
t.w = ui->maps->Tiles[i].w;
t.x = ui->maps->Tiles[i].x;
t.y = ui->maps->Tiles[i].y;

m.Tiles.append(t);
}



QFile f(filename);

if(!f.open(QIODevice::WriteOnly))
{

}else
{
QDataStream out(&f);
out.setVersion(QDataStream::Qt_4_8);

out << m.Tiles;

}

f.flush();
f.close();


How can I fix this problem and serialize?










share|improve this question

























  • At first glance the compiler tells you what's wrong. You wrote functions for MappySaver but pass MappySaver::Tile as argument.

    – vahancho
    Nov 23 '18 at 10:59











  • just create the function QDataStream& operator << (QDataStream& s, const MappySever::Tile& tile);

    – Alexander Chernin
    Nov 23 '18 at 11:48













  • @AlexanderChernin i have an error Segmentation Fault.

    – giovanni mannuoio
    Nov 23 '18 at 14:09








  • 1





    Yep, you're getting recursion there. The function is calling itself. More appropriately, you might be wanting to output individual << tile.ID, tile.x, etc?

    – TrebuchetMS
    Nov 23 '18 at 14:43








  • 1





    @TrebuchetMS Yea! Work! Tanks a lot Trebuchet. i have changend whit your example and work! image.ibb.co/f0FB5V/Immagine.png

    – giovanni mannuoio
    Nov 23 '18 at 15:09


















0















I have a problem during serialization with a simple Managed Structure.



My Class Header



class MappySaver
{

public:
MappySaver();

//structure
struct Tile
{
public:
int ID;
int x,y,w,h;
QRect rect;
};

QList<Tile> Tiles;
QObject t;
Tile tile;

};

QDataStream& operator << (QDataStream& s, const MappySaver::Tile& tile);
QDataStream& operator >> (QDataStream& s, MappySaver::Tile& tile);


#endif // MAPPYSAVER_H


and source cpp



   QDataStream &operator<<(QDataStream &s, const MappySaver::Tile& tile)
{
s << tile;
return s;
}


When I try to compile this, I get this error:




error: no match for 'operator<<' (operand types are 'QDataStream' and 'const MappySaver::Tile')




template <typename T> //QDataStream.h
QDataStream& operator<<(QDataStream& s, const QList<T>& l)
{
s << quint32(l.size());
for (int i = 0; i < l.size(); ++i)
s << l.at(i);
return s;
}


I use this class to serialize a list.
On the main form, I have a widget with the same data.



And I use this method for try to serialize.



QString filename = QFileDialog::getSaveFileName(this,
tr("Seleziona il file da salvare"),"",
tr("File Mappa (*.mp2d)"));

MappySaver::Tile t;
MappySaver m;


for(int i = 0; i < ui->maps->Tiles.count(); i++)
{
t.ID = ui->maps->Tiles[i].ID;
t.h = ui->maps->Tiles[i].h;
t.rect = ui->maps->Tiles[i].rect;
t.w = ui->maps->Tiles[i].w;
t.x = ui->maps->Tiles[i].x;
t.y = ui->maps->Tiles[i].y;

m.Tiles.append(t);
}



QFile f(filename);

if(!f.open(QIODevice::WriteOnly))
{

}else
{
QDataStream out(&f);
out.setVersion(QDataStream::Qt_4_8);

out << m.Tiles;

}

f.flush();
f.close();


How can I fix this problem and serialize?










share|improve this question

























  • At first glance the compiler tells you what's wrong. You wrote functions for MappySaver but pass MappySaver::Tile as argument.

    – vahancho
    Nov 23 '18 at 10:59











  • just create the function QDataStream& operator << (QDataStream& s, const MappySever::Tile& tile);

    – Alexander Chernin
    Nov 23 '18 at 11:48













  • @AlexanderChernin i have an error Segmentation Fault.

    – giovanni mannuoio
    Nov 23 '18 at 14:09








  • 1





    Yep, you're getting recursion there. The function is calling itself. More appropriately, you might be wanting to output individual << tile.ID, tile.x, etc?

    – TrebuchetMS
    Nov 23 '18 at 14:43








  • 1





    @TrebuchetMS Yea! Work! Tanks a lot Trebuchet. i have changend whit your example and work! image.ibb.co/f0FB5V/Immagine.png

    – giovanni mannuoio
    Nov 23 '18 at 15:09
















0












0








0








I have a problem during serialization with a simple Managed Structure.



My Class Header



class MappySaver
{

public:
MappySaver();

//structure
struct Tile
{
public:
int ID;
int x,y,w,h;
QRect rect;
};

QList<Tile> Tiles;
QObject t;
Tile tile;

};

QDataStream& operator << (QDataStream& s, const MappySaver::Tile& tile);
QDataStream& operator >> (QDataStream& s, MappySaver::Tile& tile);


#endif // MAPPYSAVER_H


and source cpp



   QDataStream &operator<<(QDataStream &s, const MappySaver::Tile& tile)
{
s << tile;
return s;
}


When I try to compile this, I get this error:




error: no match for 'operator<<' (operand types are 'QDataStream' and 'const MappySaver::Tile')




template <typename T> //QDataStream.h
QDataStream& operator<<(QDataStream& s, const QList<T>& l)
{
s << quint32(l.size());
for (int i = 0; i < l.size(); ++i)
s << l.at(i);
return s;
}


I use this class to serialize a list.
On the main form, I have a widget with the same data.



And I use this method for try to serialize.



QString filename = QFileDialog::getSaveFileName(this,
tr("Seleziona il file da salvare"),"",
tr("File Mappa (*.mp2d)"));

MappySaver::Tile t;
MappySaver m;


for(int i = 0; i < ui->maps->Tiles.count(); i++)
{
t.ID = ui->maps->Tiles[i].ID;
t.h = ui->maps->Tiles[i].h;
t.rect = ui->maps->Tiles[i].rect;
t.w = ui->maps->Tiles[i].w;
t.x = ui->maps->Tiles[i].x;
t.y = ui->maps->Tiles[i].y;

m.Tiles.append(t);
}



QFile f(filename);

if(!f.open(QIODevice::WriteOnly))
{

}else
{
QDataStream out(&f);
out.setVersion(QDataStream::Qt_4_8);

out << m.Tiles;

}

f.flush();
f.close();


How can I fix this problem and serialize?










share|improve this question
















I have a problem during serialization with a simple Managed Structure.



My Class Header



class MappySaver
{

public:
MappySaver();

//structure
struct Tile
{
public:
int ID;
int x,y,w,h;
QRect rect;
};

QList<Tile> Tiles;
QObject t;
Tile tile;

};

QDataStream& operator << (QDataStream& s, const MappySaver::Tile& tile);
QDataStream& operator >> (QDataStream& s, MappySaver::Tile& tile);


#endif // MAPPYSAVER_H


and source cpp



   QDataStream &operator<<(QDataStream &s, const MappySaver::Tile& tile)
{
s << tile;
return s;
}


When I try to compile this, I get this error:




error: no match for 'operator<<' (operand types are 'QDataStream' and 'const MappySaver::Tile')




template <typename T> //QDataStream.h
QDataStream& operator<<(QDataStream& s, const QList<T>& l)
{
s << quint32(l.size());
for (int i = 0; i < l.size(); ++i)
s << l.at(i);
return s;
}


I use this class to serialize a list.
On the main form, I have a widget with the same data.



And I use this method for try to serialize.



QString filename = QFileDialog::getSaveFileName(this,
tr("Seleziona il file da salvare"),"",
tr("File Mappa (*.mp2d)"));

MappySaver::Tile t;
MappySaver m;


for(int i = 0; i < ui->maps->Tiles.count(); i++)
{
t.ID = ui->maps->Tiles[i].ID;
t.h = ui->maps->Tiles[i].h;
t.rect = ui->maps->Tiles[i].rect;
t.w = ui->maps->Tiles[i].w;
t.x = ui->maps->Tiles[i].x;
t.y = ui->maps->Tiles[i].y;

m.Tiles.append(t);
}



QFile f(filename);

if(!f.open(QIODevice::WriteOnly))
{

}else
{
QDataStream out(&f);
out.setVersion(QDataStream::Qt_4_8);

out << m.Tiles;

}

f.flush();
f.close();


How can I fix this problem and serialize?







c++ qt serialization qdatastream






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 14:29







giovanni mannuoio

















asked Nov 23 '18 at 10:49









giovanni mannuoiogiovanni mannuoio

97




97













  • At first glance the compiler tells you what's wrong. You wrote functions for MappySaver but pass MappySaver::Tile as argument.

    – vahancho
    Nov 23 '18 at 10:59











  • just create the function QDataStream& operator << (QDataStream& s, const MappySever::Tile& tile);

    – Alexander Chernin
    Nov 23 '18 at 11:48













  • @AlexanderChernin i have an error Segmentation Fault.

    – giovanni mannuoio
    Nov 23 '18 at 14:09








  • 1





    Yep, you're getting recursion there. The function is calling itself. More appropriately, you might be wanting to output individual << tile.ID, tile.x, etc?

    – TrebuchetMS
    Nov 23 '18 at 14:43








  • 1





    @TrebuchetMS Yea! Work! Tanks a lot Trebuchet. i have changend whit your example and work! image.ibb.co/f0FB5V/Immagine.png

    – giovanni mannuoio
    Nov 23 '18 at 15:09





















  • At first glance the compiler tells you what's wrong. You wrote functions for MappySaver but pass MappySaver::Tile as argument.

    – vahancho
    Nov 23 '18 at 10:59











  • just create the function QDataStream& operator << (QDataStream& s, const MappySever::Tile& tile);

    – Alexander Chernin
    Nov 23 '18 at 11:48













  • @AlexanderChernin i have an error Segmentation Fault.

    – giovanni mannuoio
    Nov 23 '18 at 14:09








  • 1





    Yep, you're getting recursion there. The function is calling itself. More appropriately, you might be wanting to output individual << tile.ID, tile.x, etc?

    – TrebuchetMS
    Nov 23 '18 at 14:43








  • 1





    @TrebuchetMS Yea! Work! Tanks a lot Trebuchet. i have changend whit your example and work! image.ibb.co/f0FB5V/Immagine.png

    – giovanni mannuoio
    Nov 23 '18 at 15:09



















At first glance the compiler tells you what's wrong. You wrote functions for MappySaver but pass MappySaver::Tile as argument.

– vahancho
Nov 23 '18 at 10:59





At first glance the compiler tells you what's wrong. You wrote functions for MappySaver but pass MappySaver::Tile as argument.

– vahancho
Nov 23 '18 at 10:59













just create the function QDataStream& operator << (QDataStream& s, const MappySever::Tile& tile);

– Alexander Chernin
Nov 23 '18 at 11:48







just create the function QDataStream& operator << (QDataStream& s, const MappySever::Tile& tile);

– Alexander Chernin
Nov 23 '18 at 11:48















@AlexanderChernin i have an error Segmentation Fault.

– giovanni mannuoio
Nov 23 '18 at 14:09







@AlexanderChernin i have an error Segmentation Fault.

– giovanni mannuoio
Nov 23 '18 at 14:09






1




1





Yep, you're getting recursion there. The function is calling itself. More appropriately, you might be wanting to output individual << tile.ID, tile.x, etc?

– TrebuchetMS
Nov 23 '18 at 14:43







Yep, you're getting recursion there. The function is calling itself. More appropriately, you might be wanting to output individual << tile.ID, tile.x, etc?

– TrebuchetMS
Nov 23 '18 at 14:43






1




1





@TrebuchetMS Yea! Work! Tanks a lot Trebuchet. i have changend whit your example and work! image.ibb.co/f0FB5V/Immagine.png

– giovanni mannuoio
Nov 23 '18 at 15:09







@TrebuchetMS Yea! Work! Tanks a lot Trebuchet. i have changend whit your example and work! image.ibb.co/f0FB5V/Immagine.png

– giovanni mannuoio
Nov 23 '18 at 15:09














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445245%2fqt-serialization-no-match-for-operator-operand-types-are-qdatastream%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53445245%2fqt-serialization-no-match-for-operator-operand-types-are-qdatastream%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...