PDA

View Full Version : QDomElement



sabeesh
20th September 2007, 11:18
Hi,
I am using Qt 4.3.
How can I use QDomElement in Qt.4.3.

I use like this,
I declare a structure in my header file

public:
struct _Configuration {
QDomDocument Document;
QDomElement Root;
QDomElement Defaults;
QDomElement VideoDevices;
QDomElement AudioDevices;
} Configuration;


and in my .cpp file I write the code like this,

QDomElement elem;
elem = Configuration.Document.createElement("videodevice");
elem.setAttribute("name", name);
elem.setAttribute("node", node);
qDebug()<<" elem is " << elem.isNull();
Configuration.VideoDevices.appendChild(elem);

when I run my program, it display the message like this,

elem is false // elem is Not Null

Calling appendChild() on a null node does nothing.

why this message " Calling appendChild() on a null node does nothing. "
can you help me please for solving this probs.....
Thankyou

wysota
20th September 2007, 12:08
The document is probably null as well, hence calling createElement on a null node returns a null element.

sabeesh
20th September 2007, 12:43
Hi,
sorry, Not clear. Can you give an example code for this.

wysota
20th September 2007, 12:55
Example code of what? :confused:

Did you have a look at QDomDocument docs?

jpn
20th September 2007, 12:55
Here is an example straight from QDomDocument docs (detailed description part):


QDomDocument doc("MyML");
QDomElement root = doc.createElement("MyML");
doc.appendChild(root);

QDomElement tag = doc.createElement("Greeting");
root.appendChild(tag);

QDomText t = doc.createTextNode("Hello World");
tag.appendChild(t);

QString xml = doc.toString();

You cannot do it like this:


QDomElement element;
element.appendChild(child);

because the element exists no where. This is exactly what you do with "Configuration.VideoDevices". Use the QDomDocument::createElement() or its friends to construct elements.