PDA

View Full Version : Cannot open XML files processed with QDomDocument using Microsoft Word



Bodizo
30th December 2011, 12:40
After processing XML files with QDomDocument and saving them like this:


if(fileName!=""){
QFile file(fileName);
if(!file.open(QIODevice::WriteOnly)){
QMessageBox::critical(this,tr("Error"),tr("Could not open file"));
}else{
QTextStream stream(&file);
QString fdt=FDTemplate->toString();
fdt.toStdString();
stream<<fdt;
stream.flush();
file.close();
}

the files cannot be opened using Word or FrameMaker. Frame maker error is "Invalid byte"(funky signs)" of a -byte sequence". Does anyone know
what is going on? The files look fine when i open them with NotePad and NotePad++...

I read somewhere that this might be casued by QString and I've tried to convert it to std::string using .toStdString() before sending to QTextStream, but that did no help.

ChrisW67
31st December 2011, 08:51
Something is the output file is unexpected. We cannot see the file so we cannot tell you what.

You should not need to use a QTextStream or convert to QString or std::string... just use QDomDocument::toByteArray() and QIODevice::write()

Bodizo
8th January 2012, 11:31
Thanks, that helped!