Results 1 to 6 of 6

Thread: using XML to save menus?!?!

  1. #1
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face using XML to save menus?!?!

    Is it possible to save "menu definitions" in an Xml file and then read them and implement the menu of the MainWindow?

    Assume the following definition (well formed XML):

    Qt Code:
    1. //<DTD etc goes here>
    2.  
    3. <menu name="file">
    4. <menuItem>New</menuItem>
    5. <submenu name="preferences">
    6. <submenuItem>A</submenuItem>
    7. <submenuItem>B</submenuItem>
    8. </submenu>
    9. </menu>
    To copy to clipboard, switch view to plain text mode 


    How would I read this file and implement a menu out of this...I went through the doc but am not v.clear as to the syntax to use to implement a menu out of the XML file!



    Thanks in advance!

    Nupul

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using XML to save menus?!?!

    To build menu from your xml file:

    Using QDomElement read each element of your xml file. Each element that do not have any child is a QAction which is added to menu, whereas element which has one or more children is QMenu which comes under its parent (if it has one).

    You might have to maintain the list of actions and menus so that you can build xml again from your menus.
    Last edited by munna; 7th April 2006 at 07:27. Reason: Grammar Correction

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

    nupul (7th April 2006)

  4. #3
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using XML to save menus?!?!

    what is preferable...SAX or DOM and why?

  5. #4
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: using XML to save menus?!?!

    SAX is an event-based standard interface for XML parsers. The Qt interface follows the design of the SAX2 Java implementation. Its naming scheme was adapted to fit the Qt naming conventions. Details on SAX2 can be found at http://www.saxproject.org.

    DOM Level 2 is a W3C Recommendation for XML interfaces that maps the constituents of an XML document to a tree structure. Details and the specification of DOM Level 2 can be found at http://www.w3.org/DOM/. More information about the DOM classes in Qt is provided in the Qt DOM classes.

  6. #5
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: using XML to save menus?!?!

    Quote Originally Posted by nupul
    what is preferable...SAX or DOM and why?
    It's largely up to you, and is a matter of preference. They are two distinct ways of interacting with XML. I personally prefer DOM because I can treat the XML as a data structure, instead of a stream of events.

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

    Default Re: using XML to save menus?!?!

    DOM will be better in this case. In is superior to SAX in its capabilities and its only drawback is that the whole tree has to be loaded into memory (which is not the case with SAX). But I guess you won't have a dozen megabyte tree for your menus so it's not a drawback in your case.

Similar Threads

  1. How to save file with QFileDialog
    By pnikolov in forum Qt Programming
    Replies: 11
    Last Post: 1st June 2012, 10:23
  2. Replies: 2
    Last Post: 27th June 2008, 19:02
  3. Maya Style Right Click Menus in Qt
    By dvmorris in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2007, 11:55
  4. save animate to gif
    By Dmitry in forum Qt Programming
    Replies: 2
    Last Post: 16th February 2006, 16:35
  5. What does "Save All" actually save?
    By Mariane in forum Newbie
    Replies: 7
    Last Post: 31st January 2006, 13:23

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
  •  
Qt is a trademark of The Qt Company.