QT C++ Project (Creating Login with XML)

210 Views Asked by At

I have question about my internship project. They want me to create a basic Login page(ID, Password). I create a XML file for Username and Password. The program should check the XML file for username and password*. If they are correct it will direct to a second window. I'm stuck on processing XML file for username and password. How can read those information in XML file.

2

There are 2 best solutions below

0
On BEST ANSWER

As @JarMan said, I would recommend the QXmlStreamReader. You can fill it with a file (QIODevice), QString, QByteArray, etc...

Parsing a value could e.g. look like that

xml.attributes().value( attribute ).toString();

if attribute is a QString and xml is the QXmlStreamReader.

See the doc https://doc.qt.io/qt-5/qxmlstreamreader.html

0
On

There are several ways to do it. Marris mentioned one, but another one is to have this kind of code generated automatically. The way this works is that you first write an XML Schema that describes what your XML data looks like. An introduction to the XML Schema language can be found e. g. here.

Then you use an XML Schema compiler to translate the XML Schema to C++ classes. The schema compiler will also generate code to parse an XML file into objects, meaning you don't have to write any code to deal with XML by hand. It's a purely declarative approach: declare what the data looks like, and let the computer figure out the details.