qt - QFile,QFile::open: File access not specified, Opening file failed -
simple problem, can't open/create file. it's supposed save settings in xml-file given path.
i call method this:
xmlwriter->write_settings("./settings.xml");
int xmlwriter::write_settings(qstring path) { qdebug() << "path is: " + path; qdomdocument document; qdomelement root = document.createelement("settings"); document.appendchild(root); qdomelement node; node.setattribute("name", "its me!"); node.setattribute("series", "25"); node.setattribute("pmt", "200"); root.appendchild(node); qfile file(path); if(!file.open(qiodevice::readwrite, qiodevice::text)) { qdebug() << "opening file failed!"; return 1; } else { qtextstream stream(&file); stream << document.tostring(); file.close(); qdebug() << "wrote file " + path; return 0; } }
you don't pass parameters correctly, invoke polymorphic version of qfile::open
try this:
qfile file(path); if(!file.open(qiodevice::readwrite | qiodevice::text)) { qdebug() << "opening file failed!"; return 1; } else { qtextstream stream(&file); stream << document.tostring(); file.close(); qdebug() << "wrote file " + path; return 0; }
Comments
Post a Comment