Outliner to show use of DOM
This example presents a small outliner program to show the basic usage of the DOM classes. The format of the outlines is the OPML format as described in http://www.opml.org/spec. This example shows how to load a DOM tree from an XML file and how to traverse it.
Sample XML file (todos.opml):
<?xml version="1.0" encoding="ISO-8859-1"?> <opml version="1.0"> <head> <title>Todo List</title> <dateCreated>Tue, 31 Oct 2000 17:00:17 CET</dateCreated> <dateModified>Tue, 31 Oct 2000 17:00:17 CET</dateModified> <ownerName>Arthur Dent</ownerName> <ownerEmail>info@trolltech.com</ownerEmail> </head> <body> <outline text="Background"> <outline text="This is an example todo list."/> </outline> <outline text="Books to read"> <outline text="Science Fiction"> <outline text="Philip K. Dick"> <outline text="Do Androids Dream of Electical Sheep?"/> <outline text="The Three Stigmata of Palmer Eldritch"/> </outline> <outline text="Robert A. Heinlein"> <outline text="Stranger in a Strange Land"/> </outline> <outline text="Isaac Asimov"> <outline text="Foundation and Empire"/> </outline> </outline> <outline text="Qt Books (in English)"> <outline text="Dalheimer: Programming with Qt"/> <outline text="Griffith: KDE 2/Qt Programming Bible"/> <outline text="Hughes: Linux Rapid Application Development"/> <outline text="Solin: Qt Programming in 24 hours"/> <outline text="Ward: Qt 2 Programming for Linux and Windows 2000"/> </outline> </outline> <outline text="Shopping list"> <outline text="General"> <outline text="Towel"/> <outline text="Hair dryer"/> <outline text="Underpants"/> </outline> <outline text="For Sunday"> <outline text="Beef"/> <outline text="Rice"/> <outline text="Carrots"/> <outline text="Beans"/> <outline text="Beer"/> <outline text="Wine"/> <outline text="Orange juice"/> </outline> </outline> <outline text="Write a letter to Ford"> </outline> </body> </opml>
Header file (outlinetree.h):
/**************************************************************************** ** $Id: qt/outlinetree.h 3.0.6 edited Oct 12 2001 $ ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #ifndef OUTLINETREE_H #define OUTLINETREE_H #include <qlistview.h> #include <qdom.h> class OutlineTree : public QListView { Q_OBJECT public: OutlineTree( const QString fileName, QWidget *parent = 0, const char *name = 0 ); ~OutlineTree(); private: QDomDocument domTree; void getHeaderInformation( const QDomElement &header ); void buildTree( QListViewItem *parentItem, const QDomElement &parentElement ); }; #endif // OUTLINETREE_H
Implementation (outlinetree.cpp):
/**************************************************************************** ** $Id: qt/outlinetree.cpp 3.0.6 edited Oct 12 2001 $ ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "outlinetree.h" #include <qfile.h> #include <qmessagebox.h>
Main (main.cpp):
/**************************************************************************** ** $Id: qt/main.cpp 3.0.6 edited Oct 12 2001 $ ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include <qapplication.h> #include "outlinetree.h" int main( int argc, char **argv ) { QApplication a( argc, argv ); OutlineTree outline( "todos.opml" ); See also Qt XML Examples. |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 3.0 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com