Results 1 to 5 of 5

Thread: QDomElement

  1. #1
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QDomElement

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDomElement

    The document is probably null as well, hence calling createElement on a null node returns a null element.

  3. #3
    Join Date
    Jul 2007
    Posts
    166
    Thanks
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDomElement

    Hi,
    sorry, Not clear. Can you give an example code for this.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDomElement

    Example code of what?

    Did you have a look at QDomDocument docs?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDomElement

    Here is an example straight from QDomDocument docs (detailed description part):
    Qt Code:
    1. QDomDocument doc("MyML");
    2. QDomElement root = doc.createElement("MyML");
    3. doc.appendChild(root);
    4.  
    5. QDomElement tag = doc.createElement("Greeting");
    6. root.appendChild(tag);
    7.  
    8. QDomText t = doc.createTextNode("Hello World");
    9. tag.appendChild(t);
    10.  
    11. QString xml = doc.toString();
    To copy to clipboard, switch view to plain text mode 
    You cannot do it like this:
    Qt Code:
    1. QDomElement element;
    2. element.appendChild(child);
    To copy to clipboard, switch view to plain text mode 
    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.
    J-P Nurmi

  6. The following 2 users say thank you to jpn for this useful post:

    sabeesh (20th September 2007), scarecr0w132 (24th October 2013)

Similar Threads

  1. QDomElement to QByteArray ?
    By probine in forum Qt Programming
    Replies: 3
    Last Post: 2nd May 2006, 17:01
  2. The difference beteen QDomNode and QDomElement
    By elcuco in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2006, 03:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.