Results 1 to 3 of 3

Thread: Obtainin a QDomDocument from a QDomElement (4.8)

  1. #1
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Obtainin a QDomDocument from a QDomElement (4.8)

    Given a QDomElement, is there a way to obtain the QDomDocument that created it?

    The first reason I ask is that when writing functions to generate DOM nodes, I always have to pass the QDomDocument to those functions as well in order to use it to create new elements, e.g.:

    Qt Code:
    1. void SomeData::save (QDomElement &parent, QDomDocument &doc) const {
    2. // doc is needed to create child nodes, e.g.
    3. QDomElement child = doc.createElement(...);
    4. parent.appendChild(child);
    5. // ...
    6. }
    To copy to clipboard, switch view to plain text mode 

    But if there was a way to not have to pass the document, it would be a little more convenient and clean up my parameter lists a bit, e.g.:

    Qt Code:
    1. void SomeData::save (QDomElement &parent) const {
    2. QDomElement child = ???.createElement(...);
    3. parent.appendChild(child);
    4. // ...
    5. }
    To copy to clipboard, switch view to plain text mode 

    The second reason is that being able to do this with one function parameter would also lets me more easily do things like overload << and such, e.g.

    Qt Code:
    1. QDomElement & operator << (QDomElement &parent, const SomeData &data);
    To copy to clipboard, switch view to plain text mode 
    Last edited by JasonC; 5th March 2015 at 19:57. Reason: spelling corrections

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Obtainin a QDomDocument from a QDomElement (4.8)


  3. The following user says thank you to jefftee for this useful post:

    JasonC (5th March 2015)

  4. #3
    Join Date
    Feb 2012
    Posts
    10
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Obtainin a QDomDocument from a QDomElement (4.8)

    Oops. I was stuck looking for things named "document..." or "get...", never looked in the O's...

    That was so easy, thanks!!

Similar Threads

  1. Importing part of QDomDocument into QDomElement
    By bleze in forum Qt Programming
    Replies: 2
    Last Post: 4th January 2013, 08:58
  2. Split QDomDocument to new QDomDocument
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 28th January 2009, 10:59
  3. QDomDocument inside other QDomDocument
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 13th November 2008, 16:27
  4. QDomElement::elementsByTagName()
    By manojmka in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2008, 12:43
  5. QDomElement
    By sabeesh in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2007, 13:55

Tags for this Thread

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.