I have implemented my own xml writer to generate xml as QString.
i have create a class "MyXmlWriter" with private member variable as QXmlStreamWriter and try to initialize it in the public method writeToString()
in declaration header file:
class MyXmlWriter {
public:
MyXmlWriter();
~MyXmlWriter();
QString writeToString();
private:
QXmlStreamWriter writer;
void writePart();
}
in cpp file:
void MyXmlWriter::writePart() {
// i want to use the QXmlStreamWriter instance hier
}
QString MyXmlWriter::writeToString(){
QString result;
writer(&result); // at this became the error: no match for call to '(QXmlStreamWriter) (QString*)'
xmlWriter.setAutoFormatting(true);
// private method called
writePart();
return result;
}
this error appear on build: error: no match for call to (QXmlStreamWriter) (QString) writer(&result); *
If the QXmlStreamWriter write is declared in the local method writeToString() then i cant access this writer in private method writePart() i want to use the member variable "writer" in other methods that's why a local declaration isn't an option for me.
You have to assign a new object to your variable
writer, like this:This code is dangerous.
resultis destroyed at the end ofwriteToString(), sowriterthen contains invalid data and you cannot use it anymore.Additionally,
QXmlStreamWritercannot be copied, so this would probably not compile at all. It's better to just pass theQXmlStreamWriterto your methods, like this:and