My Professional Profile

I am Johnson Augustine Sr.Software Engineer and System Architect. I have 10 Yrs of hands on expertise in ASP.net MVC 5 , Angular 5 , C# MVC Razor, WPF MVVM , Android , IOS Swift 3 , IOS11 MSSQL,MySQL Database,,PHP,C/C++/Visual C++/G++/QT++,Com,DirectX,Open CV,EMGU CV , embedded System Development , [Raspberry PI]. ,html,Javascript,Jquery,Ajax.CSS , Networking ,Cyber security, Ethical Hacking You can see my professional profile at http://linkedin.com/in/johnsontaugustine Email : johnsonaugustine@live.com

Sunday, 28 July 2013

How to convert Qstring to const char * in qt

To convert Qstring to const char *

String variable.toStdstring.c_str();


Reading XML in QT5

Reading xml in the format
XML will be look like 
<xml>
<settings name=john > </settings></xml>

#include <qdom.h>
#include <qfile.h>
#include <qfile.h>
#include <qstring.h>
#include <iostream>
#include <QTextStream>

QString  SetUrl()
{
          QString str;
          QDomDocument Settingsdoc( "demo.xml" );
          QFile file( "EmSettings.xml" );
          if( !file.open(QIODevice::ReadOnly ) )
          QTextStream(stdout) << "Error reading settings file"<< endl;
          if( !Settingsdoc.setContent( &file ) )
          {
            file.close();

          }
          file.close();
          QDomElement root = Settingsdoc.documentElement();
          QDomNodeList list  =root.elementsByTagName("settings");
          str = list.at(0).toElement().attribute("name");
          QTextStream(stdout) << "URL "<< str<< endl;
          Settingsdoc.clear();
           return str;
}

2) Read xml in the format

<xml>
<name>John</name>
<add>Demo</add>


Answer

QDomDocument Settingsdoc( "demo1" );
      QFile file( "demo.xml" );
      if( !file.open(QIODevice::ReadOnly ) )
        return -1;
      if( !Settingsdoc.setContent( &file ) )
      {
        file.close();
        return -2;
      }
      file.close();

      QDomElement root = Settingsdoc.documentElement();
      QDomNodeList list  =root.elementsByTagName("name");
      int count = list.count();
      for (int i = 0; i < count; i++)
          {
            QString str = list.at(i).toElement().text();
            QTextStream(stdout) << "Value "<< str<< endl;
          }