int Generate_Xml::rewriteXMLFile(QVector<QLineEdit *> p,int j,int track_tabsibling) { bool tab; int tab_get; QFile Default("default1.xml"); QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(); QXmlStreamWriter *newline = new QXmlStreamWriter(); xmlWriter->setDevice(&Default); newline->setDevice(&Default); xmlWriter->setAutoFormatting (true); xmlWriter->setAutoFormatting(true); tab=xmlWriter->autoFormatting(); xmlWriter->setAutoFormattingIndent(-10); tab_get=xmlWriter->autoFormattingIndent(); if (!Default.open(QIODevice::Append)) { /* show wrror message if not able to open file */ QMessageBox::warning(0, "Read only", "The file is in read only mode"); } QString temp1; QString temp2; temp1=(p.at(j))->displayText(); newline->writeEndDocument(); for(int i=0;i<track_tabsibling;i++)//changed tab here actaully multiplied by two xmlWriter->writeCharacters("\t"); xmlWriter->writeStartElement(temp1); j++; while(p.at(j)!=0) { temp1=(p.at(j))->displayText(); j++; temp2=(p.at(j))->displayText(); j++; xmlWriter->writeAttribute(temp1,temp2); } xmlWriter->writeEndElement(); Default.close(); delete xmlWriter; delete newline; return j; }
QString AlterNote::wrap() { QString returnValue; QXmlStreamWriter *writer = new QXmlStreamWriter(&returnValue); writer->setAutoFormatting(true); writer->setCodec("UTF-8"); writer->writeStartDocument(); writer->writeDTD("<!DOCTYPE NixNote-Query>"); writer->writeStartElement("nixnote-alternote"); writer->writeAttribute("version", "2"); writer->writeAttribute("application", "NixNote"); writer->writeAttribute("applicationVersion", "2.x"); writer->writeStartElement("AlterNote"); for (int i=0; i<lids.size(); i++) writer->writeTextElement("id", QString::number(lids[i])); writer->writeTextElement("Notebook", notebook); writer->writeTextElement("Query", query); for (int i=0; i<addTagNames.size(); i++) writer->writeTextElement("AddTag", addTagNames[i]); for (int i=0; i<delTagNames.size(); i++) writer->writeTextElement("DelTag", delTagNames[i]); if (clearReminder) writer->writeTextElement("ClearReminder", "true"); if (reminderCompleted) writer->writeTextElement("ReminderComplete", "true"); writer->writeEndElement(); writer->writeEndElement(); writer->writeEndDocument(); return returnValue; }
bool Document::save(const QString& to) { QString file = !to.isEmpty() ? to : _fileName; if (!file.endsWith(".kst")) { file.append(".kst"); } QFile f(file); if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) { _lastError = QObject::tr("File could not be opened for writing."); return false; } Q_ASSERT(objectStore()); objectStore()->cleanUpDataSourceList(); _fileName = file; QXmlStreamWriter xml; xml.setDevice(&f); xml.setAutoFormatting(true); xml.writeStartDocument(); xml.writeStartElement("kst"); xml.writeAttribute("version", "2.0"); xml.writeStartElement("data"); foreach (DataSourcePtr s, objectStore()->dataSourceList()) { s->saveSource(xml); }
/* Zapisuje ca³y kontener do pliku XML Ka¿da para atrybut wartoœæ ma tak¹ sam¹ reprezentacjê w pliku XML. Obiekty s¹ rozró¿niane za pomoc¹ tag'u rozpoczynaj¹cego który okreœla typ. W przypadku komplikacji wyœwietlany jest MessageBox */ void MK::saveToFile(std::string filename){ QFile file(filename.c_str()); if (!file.open(QIODevice::WriteOnly)){ QMessageBox::warning(0,"B³¹d pliku", "Plik jest zablokowany przed zapisem", QMessageBox::Ok); } else { QXmlStreamWriter* xmlWriter = new QXmlStreamWriter(); xmlWriter->setDevice(&file); xmlWriter->setAutoFormatting(true); xmlWriter->writeStartDocument(); xmlWriter->writeStartElement("eksponaty"); MKontener::iterator mk_it; QList<QPair<QString, QString> >::iterator it; QList<QPair<QString, QString> > l_toFile; mk_it = m_kontener.begin(); while( mk_it!=m_kontener.end() ){ l_toFile = (*mk_it)->saveElement(); it = l_toFile.begin(); xmlWriter->writeStartElement(l_toFile[1].second.simplified().replace(" ","")); while (it != l_toFile.end() ){ xmlWriter->writeAttribute((*it).first.simplified().replace(" ",""),(*it).second); it++; } xmlWriter->writeEndElement(); mk_it++; } xmlWriter->writeEndElement(); xmlWriter->writeEndDocument(); } }
bool ConfigXml::writeConfigFile(const QString fileName) { QXmlStreamWriter writer; QFile configFile(fileName); if (!configFile.open(QFile::Truncate | QFile::WriteOnly | QFile::Text)) { qDebug() << "Error: Cannot write file " << qPrintable(fileName) << ": " << qPrintable(configFile.errorString()); return false; } writer.setDevice(&configFile); writer.setAutoFormatting(true); writer.writeStartDocument(); writer.writeStartElement("config"); writeEntries(&writer); writer.writeEndDocument(); configFile.close(); if (configFile.error()) { qDebug() << "Error: Cannot write file " << qPrintable(fileName) << ": " << qPrintable(configFile.errorString()); return false; } return true; }
int main ( int argc, char** argv ) { QApplication app(argc, argv ); QFile wiki ( "../tests/input.wiki" ); QFile html ( "output.html" ); if ( wiki.open ( QIODevice::ReadOnly ) && html.open ( QIODevice::WriteOnly ) ) { StateMachineBase::Context ctx; QXmlStreamWriter qout ( &html ); qout.setAutoFormatting(true); qout.writeStartDocument(); qout.writeStartElement("html"); qout.writeStartElement("head"); qout.writeEndElement(); qout.writeStartElement("body"); ctx.lexer = new WikiLexer; ctx.observer = new XHTMLObserver ( "", &qout ); ctx.nextState = new Parser; ctx.lexer->setInput ( QString::fromUtf8( wiki.readAll() ) ); ctx.observer->startPage( "Test Wiki" ); while ( ctx.nextState != 0 ) ctx.nextState->exec ( &ctx ); ctx.observer->endPage(); qout.writeEndDocument(); html.close(); QDesktopServices::openUrl ( html.fileName() ); wiki.close(); } }
bool HtmlExporter::startFile(QFile& file, const QString& basename, QXmlStreamWriter& stream, int currentPage, int totalPages) { if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) { errorHandler->handleIOError(file); return false; } stream.setDevice(&file); stream.setAutoFormatting(true); stream.setAutoFormattingIndent(2); stream.setCodec("utf-8"); // Get the CSS either from the resources or from the settings directory writeHtmlStart(stream, atools::settings::Settings::getOverloadedPath(":/littlenavmap/resources/css/export.css")); writeHtmlHeader(stream); writeHtmlNav(stream, basename, currentPage, totalPages); stream.writeStartElement("table"); stream.writeStartElement("tbody"); return true; }
void init( QFile &file, QXmlStreamWriter &stream ) { stream.setDevice( &file ); stream.setAutoFormatting(true); stream.writeStartDocument("1.0"); stream.writeDTD("<!DOCTYPE IMAGE>"); stream.writeStartElement("image"); }
void Xml_Generator::nowSave() { QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(); QFile Default("default.xml"); Default.open(QIODevice::Append); xmlWriter->setDevice(&Default); xmlWriter->writeStartElement("/ProjectDefinition"); xmlWriter->writeCharacters(" "); xmlWriter->setAutoFormatting (true); xmlWriter->setAutoFormatting(true); Default.close(); delete xmlWriter; QMessageBox::warning(0, "Saved Status", "Your file has been saved by the name default1.xml"); }
QString MessageXmlParser::composeXml (AbstractXmlData* data) { QString xml; QXmlStreamWriter writer (&xml); writer.setAutoFormatting (true); writer.writeStartDocument(); writer.writeTextElement ("message", static_cast<MessageXmlData*>(data)->message); writer.writeEndDocument(); return xml; }
bool ROSUtils::gererateQtCreatorWorkspaceFile(QXmlStreamWriter &xmlFile, const QStringList &watchDirectories, const QStringList &includePaths) { xmlFile.setAutoFormatting(true); xmlFile.writeStartDocument(); xmlFile.writeStartElement(QLatin1String("Workspace")); xmlFile.writeStartElement(QLatin1String("WatchDirectories")); foreach (QString str, watchDirectories) { xmlFile.writeTextElement(QLatin1String("Directory"), str); }
bool SM_ModelBackend::saveToXmlStream(QXmlStreamWriter &stream) { stream.setAutoFormatting(true); stream.writeStartDocument(); stream.writeStartElement("SubnetMap"); stream.writeAttribute("fileformat", "2"); stream.writeAttribute("writer", "SubnetMapper"); stream.writeAttribute("version", qApp->applicationVersion().toUtf8()); for (int row = 0; row < SubnetList.count(); ++row) { Subnet *subnet = SubnetList.at(row); stream.writeStartElement("subnet"); if (subnet->getIPversion()==Subnet::IPv4) { quint32 momip = ((Subnet_v4*)subnet)->getIP(); quint32 momnm = ((Subnet_v4*)subnet)->getNM(); QColor momcol = subnet->getColor(); stream.writeAttribute("ipversion","IPv4"); stream.writeTextElement("identifier",subnet->getIdentifier()); stream.writeTextElement("address",((Subnet_v4*)subnet)->IP2String(momip)); stream.writeTextElement("netmask",((Subnet_v4*)subnet)->IP2String(momnm)); stream.writeTextElement("description",subnet->getDescription()); stream.writeTextElement("notes",subnet->getNotes()); stream.writeTextElement("color",momcol.name()); } else { QPair<quint64,quint64> momip = ((Subnet_v6*)subnet)->getIP(); QPair<quint64,quint64> momnm = ((Subnet_v6*)subnet)->getNM(); QColor momcol = subnet->getColor(); stream.writeAttribute("ipversion","IPv6"); stream.writeTextElement("identifier",((Subnet_v6*)subnet)->getIdentifier()); stream.writeTextElement("address",((Subnet_v6*)subnet)->IP2String(momip)); stream.writeTextElement("netmask",((Subnet_v6*)subnet)->IP2String(momnm)); stream.writeTextElement("description",((Subnet_v6*)subnet)->getDescription()); stream.writeTextElement("notes",((Subnet_v6*)subnet)->getNotes()); stream.writeTextElement("color",momcol.name()); } stream.writeEndElement(); // Element: subnet } stream.writeEndElement(); // Element: SubnetMapper2 stream.writeEndDocument(); return true; }
bool CParseChannelSettingConfig::SaveFile() { QString tempFile = "channel_temp.xml"; if( QFile::exists( tempFile ) ) { if( !QFile::remove( tempFile ) ) return false; } QFile writeFile( tempFile ); if( !writeFile.open(QFile::ReadWrite| QFile::Text) ) return false; QXmlStreamWriter XmlWrite; XmlWrite.setDevice( &writeFile ); XmlWrite.setAutoFormatting( true ); XmlWrite.writeStartDocument(); XmlWrite.writeStartElement( ROOT_NODE ); int nCount = m_vecNewChannelSettingInfo.count(); for( int i=0; i<nCount; ++i ) { CHANNEL_SETTING_INFO channelSettingInfo =m_vecNewChannelSettingInfo[i]; XmlWrite.writeStartElement( CHANNEL_NODE ); XmlWrite.writeTextElement( NUM_NODE, QString::number(channelSettingInfo.nChannelNum) ); XmlWrite.writeTextElement( QUALITY_NODE, QString::number(channelSettingInfo.enuQuality) ); XmlWrite.writeTextElement( RTMP_ENABLE_NODE1, QString::number(channelSettingInfo.bRtmpEnable1? 1:0) ); XmlWrite.writeTextElement( RTMP_ADDR_NODE1, channelSettingInfo.strRtmpAddr1 ); XmlWrite.writeTextElement( RTMP_AUDIO_DELAY_NODE1, QString::number(channelSettingInfo.nRtmpAudioDelay1) ); XmlWrite.writeTextElement( RTMP_ENABLE_NODE2, QString::number(channelSettingInfo.bRtmpEnable2? 1:0) ); XmlWrite.writeTextElement( RTMP_ADDR_NODE2, channelSettingInfo.strRtmpAddr2 ); XmlWrite.writeTextElement( RTMP_AUDIO_DELAY_NODE2, QString::number(channelSettingInfo.nRtmpAudioDelay2) ); XmlWrite.writeTextElement( UDP_RTP_ENABLE_NODE, QString::number(channelSettingInfo.bUdpOrRtpEnable? 1:0) ); XmlWrite.writeTextElement( UDP_RTP_ADDR_NODE, QString::number(channelSettingInfo.bUdpOrRtpAddr?1:0) ); XmlWrite.writeTextElement( UDP_RTP_IP_NODE, channelSettingInfo.strUdpOrRtpIp ); XmlWrite.writeTextElement( UDP_RTP_PORT_NODE, QString::number(channelSettingInfo.nUdpOrRtpPort) ); XmlWrite.writeTextElement( UDP_RTP_AUDIO_DELAY_NODE, QString::number(channelSettingInfo.nUdpOrRtpAudioDelay) ); XmlWrite.writeTextElement( INPUT_VIDEO_FORMAT_NODE, QString::number(channelSettingInfo.nInputVideoFormat)); XmlWrite.writeTextElement( OUTPUT_VIDEO_FORMAT_NODE, QString::number(channelSettingInfo.nOutputVideoFormat)); XmlWrite.writeEndElement(); } XmlWrite.writeEndDocument(); writeFile.close(); // 临时文件写完后,将临时文件copy到备份文件 QString strSaveFile = CHANNEL_SETTING_CONFIG_FILE; QFile::remove( strSaveFile ); bool bRet = QFile::rename( tempFile, strSaveFile ); sync(); return bRet; }
void SoundSettings::saveXML ( const QString &xmlFileName, const QString &origFileName, const QString ©FileName, const QString &title) { QXmlStreamWriter *writer; QFile file (xmlFileName); SYS_DEBUG ("-----------------------------------------------------"); SYS_DEBUG ("*** xmlFileName = %s", SYS_STR(xmlFileName)); if (!file.open(QIODevice::WriteOnly)) { SYS_WARNING ("Unable to open file for writing: %s", SYS_STR(xmlFileName)); return; } /* * */ writer = new QXmlStreamWriter(); writer->setDevice (&file); writer->setAutoFormatting(true); writer->setCodec ("UTF-8"); writer->writeStartDocument (); writer->writeStartElement ("soundsettings-applet"); writer->writeStartElement("orig-file"); writer->writeCharacters (origFileName); writer->writeEndElement (); writer->writeStartElement("copy-file"); writer->writeCharacters (copyFileName); writer->writeEndElement (); writer->writeStartElement("title"); writer->writeCharacters (title); writer->writeEndElement (); /* * */ writer->writeEndElement(); writer->writeEndDocument(); delete writer; file.close (); }
bool NPushReportSpeed::save_to_dir(QString &dirName) { QString reportFilename = (dirName + FSC_FSYS_SLASH) + "Speed.xml"; QFile reportFile(reportFilename); reportFile.open(QFile::WriteOnly | QFile::Text); QXmlStreamWriter xml; xml.setDevice(&reportFile); xml.setAutoFormatting(true); xml.writeStartDocument(); dataAccessMutex.lock(); xml.writeStartElement("SpeedReport"); xml.writeStartElement("stats"); xml.writeAttribute("max", QString::number(Speed_max)); xml.writeAttribute("avg", QString::number(Speed_avg)); xml.writeEndElement();//stats xml.writeStartElement("graph"); SelfShrinkingList::iterator it; for(it = graphPoints.begin(); it != graphPoints.end() ; ++it) { xml.writeStartElement("point"); xml.writeAttribute("val", QString::number(*it)); xml.writeEndElement(); } xml.writeEndElement();//graph xml.writeEndElement();//SpeedReport dataAccessMutex.unlock(); xml.writeEndDocument(); reportFile.close(); qDebug() << "Speed -> Ended"; return true; }
/** * Creates the current configuration string. * @return * The string. */ QString CreateSceFile::createCurrentConfigurationString() { QBuffer xmlBuffer; QXmlStreamWriter xmlWriter; xmlWriter.setAutoFormatting(true); xmlWriter.setAutoFormattingIndent(2); xmlBuffer.open(QIODevice::WriteOnly); xmlWriter.setDevice(&xmlBuffer); xmlWriter.writeStartElement("SceConfiguration"); xmlWriter.writeStartElement("Files"); for(int i = 0; i < ui->filesTableWidget->rowCount(); i++) { QComboBox* box = static_cast<QComboBox*>(ui->filesTableWidget->cellWidget(i, COLUMN_TYPE)); QString subDirectory = ui->filesTableWidget->item(i, COLUMN_SUBDIR)->text(); QString source = MainWindow::convertToRelativePath(m_configFileName, ui->filesTableWidget->item(i, COLUMN_SOURCE)->text()); xmlWriter.writeStartElement("File"); xmlWriter.writeAttribute("subDirectory", subDirectory); xmlWriter.writeAttribute("type", box->currentText()); xmlWriter.writeAttribute("source", source); xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); xmlWriter.writeStartElement("ScriptArguments"); for(int i = 0; i < ui->argumentsListWidget->count(); i++) { xmlWriter.writeStartElement("ScriptArgument"); xmlWriter.writeAttribute("value", ui->argumentsListWidget->item(i)->text()); xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); xmlWriter.writeStartElement("ScriptWindowState"); xmlWriter.writeAttribute("withScriptWindow", QString("%1").arg(ui->withScriptWindowCheckBox->isChecked())); xmlWriter.writeAttribute("notMinimized", QString("%1").arg(ui->notMinimized->isChecked())); xmlWriter.writeAttribute("minScVersion", QString("%1.%2").arg(ui->minScVersionMajor->value()).arg(ui->minScVersionMinor->value())); xmlWriter.writeAttribute("sceFileName", MainWindow::convertToRelativePath(m_configFileName, ui->fileLineEdit->text())); xmlWriter.writeEndElement(); xmlWriter.writeEndElement();//SceConfiguration return xmlBuffer.data(); }
bool VarParser::buildXML() { QXmlStreamWriter xmlWriter; if(readMapFile()) { xmlWriter.setAutoFormatting(true); if(!PathStorage::getBuildDir().contains(QRegExp("[\\w\\d]+"))) return false; QFile file(PathStorage::getBuildDir()+"/variables.xml"); if (!file.open(QIODevice::WriteOnly)) {return false;} else { xmlWriter.setDevice(&file); /* Writes a document start with the XML version number. */ xmlWriter.writeStartDocument(); xmlWriter.writeStartElement("mapForDebug"); foreach (FundamentalType* fType, fundTypes) { xmlWriter.writeStartElement("FundamentalType"); xmlWriter.writeAttribute("id",QString::number(fType->getId())); xmlWriter.writeAttribute("name",fType->getName()); xmlWriter.writeAttribute("size",QString::number(fType->getSize())); xmlWriter.writeEndElement(); } foreach (Array* aType, arrays) { xmlWriter.writeStartElement("Array"); xmlWriter.writeAttribute("id",QString::number(aType->getId())); xmlWriter.writeAttribute("type",QString::number(aType->getType())); xmlWriter.writeAttribute("size",QString::number(aType->getSize())); xmlWriter.writeAttribute("count",QString::number(aType->getCnt())); xmlWriter.writeEndElement(); } foreach (Structure* sType, structs) { xmlWriter.writeStartElement("Struct"); xmlWriter.writeAttribute("id",QString::number(sType->getId())); xmlWriter.writeAttribute("name",sType->getName()); xmlWriter.writeAttribute("size",QString::number(sType->getSize())); for(int i=0;i<sType->getMembers().count();i++) { xmlWriter.writeStartElement("FieldID"); xmlWriter.writeAttribute("type",QString::number(sType->getMembers().at(i))); xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); }
void QuteWidget::createXmlWriter(QXmlStreamWriter &s) { s.setAutoFormatting(true); s.writeStartElement("bsbObject"); s.writeAttribute("type", getWidgetType()); s.writeAttribute("version", QCS_CURRENT_XML_VERSION); // Only for compatibility with blue (absolute values) s.writeTextElement("objectName", m_channel); s.writeTextElement("x", QString::number(x())); s.writeTextElement("y", QString::number(y())); s.writeTextElement("width", QString::number(width())); s.writeTextElement("height", QString::number(height())); s.writeTextElement("uuid", property("QCS_uuid").toString()); s.writeTextElement("visible", property("QCS_visible").toBool() ? "true":"false"); s.writeTextElement("midichan", QString::number(property("QCS_midichan").toInt())); s.writeTextElement("midicc", QString::number(property("QCS_midicc").toInt())); }
bool svg_writer::write_to_file (const QString &filename, const abstract_svg_item *root) { QFile file (filename); if (!file.open (QIODevice::WriteOnly)) return false; QXmlStreamWriter writer (&file); writer.setAutoFormatting(true); map<QString, QString> namespaces = get_used_namespaces (root); for (auto namespace_pair : namespaces) writer.writeNamespace (namespace_pair.first, namespace_pair.second); writer.writeDefaultNamespace (svg_namespaces::svg_uri ()); writer.writeStartDocument(); write_item (root, writer); writer.writeEndDocument(); return true; }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); qDebug()<< "jjdjjd"; QFile *file = new QFile("settings.xml"); if(!file->open(QIODevice::ReadWrite | QIODevice::Text)) { qDebug() << "Could not open the XML File"; return -1; } QXmlStreamReader *reader = new QXmlStreamReader(file); QXmlStreamWriter *writer = new QXmlStreamWriter(file); while(!reader->atEnd() && !reader->hasError()) { QXmlStreamReader::TokenType token = reader->readNext(); if(token == QXmlStreamReader::StartDocument) continue; if(token == QXmlStreamReader::StartElement) { if(reader->name() == "IsSetting") { QString str = reader->readElementText(); if(str == "True") { //continue } else { writer->setAutoFormatting(true); writer->writeStartDocument(); writer->writeStartElement("Application"); writer->writeTextElement("IP", "192.168.2.45"); } } } } return a.exec(); }
void classepub::epubCreatIndex() { QFile fileX(QDir::homePath()+"/.kirtasse/download/title.xml"); if (!fileX.open(QFile::WriteOnly | QFile::Text)) { return ; } QXmlStreamWriter stream; stream.setDevice(&fileX); stream.setAutoFormatting(true); stream.writeStartDocument(); stream.writeStartElement("dataroot"); int cnt=m_listEpub.count(); for (int i=0;i<cnt ;i++){ QString line= m_listEpub.at(i); QString tit=line.section("|",0,0); QString id=line.section("|",1,1); QString lvl=line.section("|",2,2); int newid=m_listId.indexOf(id); if (newid==-1){newid=0;} QVariant dd= newid+1; id=dd.toString(); //qDebug()<<id; stream.writeStartElement("title"); stream.writeTextElement("tit", tit); stream.writeTextElement("lvl", lvl); stream.writeTextElement("id", id); stream.writeEndElement(); } stream.writeEndElement(); // dataroot stream.writeEndDocument(); QDir dir; //QProcess prosses; // QString pathToExtract=QDir::homePath()+"/.kirtasse/xbook/epub"; // if (dir.exists(pathToExtract)) //التاكد من وجود مجلد المؤقت // { // prosses.execute("rm -r "+pathToExtract); // prosses.waitForFinished(); // } m_listEpub.clear(); }
//Variante 2: XML in eigene Datei schreiben und orientation und sizes extra sichern: void RackWindow::saveSplittertoXML(RSplitter *splitter) { QXmlStreamWriter xml; xml.setAutoFormatting(true); //needs change!!!!!! for cross platform QFile file("/home/rf/rack.xml"); if (!file.open(QFile::WriteOnly | QFile::Text)) { qDebug() << "Error xml"; return; } xml.setDevice(&file); xml.writeStartDocument(); xml.writeDTD("<!DOCTYPE xml>"); xml.writeStartElement("racklayout"); xml.writeAttribute("version", "1.0"); saveSplitterItemtoXML(splitter, &xml); xml.writeEndDocument(); }
/*********************************** * Writes application version info ***********************************/ void WriteAppInfo(QString Filename, QString MajorVersion, QString MinorVersion) { QString FileName = QApplication::applicationDirPath() + QDir::separator() + Filename; if(FileName.isEmpty()) return; QFile File(FileName); if (!File.open(QIODevice::WriteOnly)) { qDebug() << "Cannot open file"; return; //Cannot open file } /*if file is successfully opened then create XML*/ QXmlStreamWriter* XmlWriter = new QXmlStreamWriter(); XmlWriter->setAutoFormatting(true); /* set the file */ XmlWriter->setDevice(&File); /* Writes a document start with the XML version number version. */ XmlWriter->writeStartDocument(); XmlWriter->writeStartElement("Info"); /* Now write the version */ XmlWriter->writeStartElement("Major_Version"); XmlWriter->writeCharacters(MajorVersion); XmlWriter->writeEndElement(); XmlWriter->writeStartElement("Minor_Version"); XmlWriter->writeCharacters(MinorVersion); XmlWriter->writeEndElement(); XmlWriter->writeEndElement(); XmlWriter->writeEndDocument(); File.flush(); File.close(); delete XmlWriter; }
void Gitarre::WriteSavedRepos () { QFile saveFile (UserDataDir.absolutePath() + "/repos"); saveFile.open (QIODevice::WriteOnly | QIODevice::Text); if (saveFile.isOpen()) { QXmlStreamWriter writer (&saveFile); writer.setAutoFormatting(true); writer.writeStartDocument("1.0"); writer.writeStartElement ("saves"); for (unsigned int i = 0; i < Repos.size(); ++i) { writer.writeStartElement ("repository"); writer.writeAttribute ("path", Repos[i]->GetDir().absolutePath()); writer.writeEndElement (); } writer.writeEndDocument(); saveFile.close(); } }
void PaSettings::apply() { this->beamerIP= this->ui->beamerIPLineEdit->text(); if(settingsFile->open(QIODevice::WriteOnly)) { QXmlStreamWriter write; write.setDevice(settingsFile); write.setAutoFormatting(true); write.writeStartDocument(); write.writeStartElement("settings"); write.writeTextElement("beamerIP",beamerIP); write.writeEndElement(); write.writeEndDocument(); } else { qDebug()<<settingsFile->errorString(); } settingsFile->close(); }
// This function creates the first network and save it in the QFile fi void TestXmlParsing::createNetwork1(NeuralNetwork *network1, QFile *fi) { network1->setMathFunction(stringToMathFunction("10*x/(1+(x*x)")); // Creation of the list of the layers sizes QList<int> *numbers = new QList <int> ; numbers->push_back(2); numbers->push_back(5); numbers->push_back(3); // Creation of the layers network1->createLayerList(numbers); delete numbers ; network1->linkLayers(true); // Writing file fi->open(QIODevice::ReadWrite) ; QXmlStreamWriter *stream = new QXmlStreamWriter(fi); stream->setAutoFormatting(true); stream->writeStartDocument(); writeXML(network1, stream) ; stream->writeEndDocument(); delete stream ; fi->close(); }
void Rete::saveRete(string s){ QFile* file = new QFile("../../../rete.xml"); // se file esiste lo provo ad aprire (sola scrittura e di tipo testuale (con "a capo" \n)) if(!file->open(QIODevice::WriteOnly | QIODevice::Text)){ QMessageBox err; err.setText("ERRORE APERTURA FILE"); err.exec(); } else{ //creo un xmlStreamWrite (sistema di scrittura per file xml) QXmlStreamWriter* in = new QXmlStreamWriter; //abilito la formattazione automatica in modo da avere un xml indentato e spaziato da righe in->setAutoFormatting(true); //gli passo il file xml in cui scrivere in->setDevice(file); // scrivo l'intestazione del file xml in->writeStartDocument(); // scrivo il tag radice in->writeStartElement("reti"); //tag identificativo per ogni utente nella rete in->writeStartElement("rete"); in->writeTextElement("user", QString::fromStdString(s)); // scorro il database e salvo ogni user nel file for(vector<Utente*>::const_iterator it = friends.begin(); it != friends.end(); ++it){ in->writeTextElement("username", QString::fromStdString((*it)->getLogin()));} //tag di chiusura (</user> in questo caso) in->writeEndElement(); // Essendo qui, ho finito gli utenti del db e chiudo tag radice (</reti>) in->writeEndElement(); // Chiudo il documento in->writeEndDocument(); // Chiudo il file file->close();} }
void Generate_Xml::CreateXMLFile(QString s) { QFile Default("default1.xml"); QXmlStreamWriter *xmlWriter = new QXmlStreamWriter(); Default.remove(); if (!Default.open(QIODevice::Append)) { /* show wrror message if not able to open file */ QMessageBox::warning(0, "Read only", "The file is in read only mode"); } else { std::string p= s.toStdString(); std::cout << p; std::cout << "You are now writing to the file"; xmlWriter->setAutoFormatting (true); xmlWriter->setDevice(&Default); xmlWriter->writeStartDocument(); xmlWriter->writeStartElement("ProjectDefinition"); xmlWriter->writeAttribute("name",s);//This is only useful xmlWriter->writeCharacters(" "); Default.close(); //xmlWriter->writeEndElement(); /*xmlWriter->writeEndDocument();*/ } delete xmlWriter; }
void Utilisateur::saveParam(){ QFile output("../parametres.xml"); if(output.open(QIODevice::WriteOnly)){ QXmlStreamWriter stream (&output); stream.setAutoFormatting(true); stream.writeStartDocument(); stream.writeStartElement("Type"); stream.writeAttribute("Entier",QString(_entier?"True":"False")); stream.writeAttribute("Reel",QString(_reel?"True":"False")); stream.writeAttribute("Rationnel",QString(_rationnel?"True":"False")); stream.writeAttribute("Complexe",QString(_complexe?"True":"False")); stream.writeAttribute("Degre",QString(_degre?"True":"False")); stream.writeEndElement(); stream.writeStartElement("Pile"); stream.writeAttribute("X",QString::number(_X)); stream.writeAttribute("Affichage",QString(_pile?"True":"False")); stream.writeEndElement(); stream.writeStartElement("Clavier"); stream.writeAttribute("Affichage",QString(_clavier?"True":"False")); stream.writeEndElement(); /*for(unsigned int i=0;i<_X;i++) { Constante* c = new Constante(_pile->depiler()); QString xml = c->toXML(); stream.writeCharacters(xml); }*/ stream.writeEndDocument(); } output.close(); }
void Core::SaveDefs() { QFile file(Configuration::GetConfigurationPath() + "users.xml"); if (QFile(Configuration::GetConfigurationPath() + "users.xml").exists()) { QFile(Configuration::GetConfigurationPath() + "users.xml").copy(Configuration::GetConfigurationPath() + "users.xml~"); QFile(Configuration::GetConfigurationPath() + "users.xml").remove(); } if (!file.open(QIODevice::Truncate | QIODevice::WriteOnly)) { Huggle::Syslog::HuggleLogs->ErrorLog("Can't open " + Configuration::GetConfigurationPath() + "users.xml"); return; } WikiUser::TrimProblematicUsersList(); int x = 0; QXmlStreamWriter *writer = new QXmlStreamWriter(); writer->setDevice(&file); writer->setAutoFormatting(true); writer->writeStartDocument(); writer->writeStartElement("definitions"); WikiUser::ProblematicUserListLock.lock(); while (x<WikiUser::ProblematicUsers.count()) { writer->writeStartElement("user"); writer->writeAttribute("name", WikiUser::ProblematicUsers.at(x)->Username); writer->writeAttribute("badness", QString::number(WikiUser::ProblematicUsers.at(x)->GetBadnessScore(false))); writer->writeEndElement(); x++; } WikiUser::ProblematicUserListLock.unlock(); writer->writeEndElement(); writer->writeEndDocument(); file.close(); delete writer; QFile().remove(Configuration::GetConfigurationPath() + "users.xml~"); }