Results 1 to 5 of 5

Thread: Problem with Model/View

  1. #1
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Talking Problem with Model/View

    I have parsed an XML file and got this,
    Qt Code:
    1. class Element
    2. {
    3. public:
    4. Element(const QString &type)
    5. :ElementType(type)
    6. {
    7. content.clear();
    8. }
    9.  
    10. ~Element(void) {}
    11.  
    12. void addContent(const QString str);
    13. void addSubElement(Element* element);
    14. void addAttr(const QString attr, const QString value);
    15. void toText(QTextStream &os, int level); //print for testing
    16.  
    17. private:
    18. QString ElementType, content;
    19. QList<Element*> list_subElement;
    20. QMap<QString, QString> map_attr;
    21. };
    To copy to clipboard, switch view to plain text mode 
    ElementType represents the name of the tag, content represents the value of this tag,
    every element also has many attribute-value pair, which are represented by the QMap,
    the child element is represented by the QList<Element*>

    For this simple XML file:
    [HTML]<Class No.="02">
    <Student No.="0215">Mike Jasen</Student>
    </Class>[/HTML]

    My Problem is:
    I want to show the Element and child elements in a tree-view. If any element is clicked in this tree-view, the attribute-value pairs can be shown in the table-view. How can I implement this?
    This pic is want I want, I draw it using photofiltre
    Attached Images Attached Images

  2. #2
    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: Problem with Model/View

    How about writing a model interface around QDomDocument? I mean, with QDom* you already got a readily available XML tree representation.
    J-P Nurmi

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

    Shawn (28th August 2007)

  4. #3
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with Model/View

    Quote Originally Posted by jpn View Post
    How about writing a model interface around QDomDocument? I mean, with QDom* you already got a readily available XML tree representation.
    I start this project without any guidance. I mean when I release that DOM is better, I have already gone that far...

    At the very begining I used to use lots of struct to represent the element, that's realy a disaster...

    Maybe my problem exsits in how to give the value to the Model? The list member and the map member should be given to different Model?

  5. #4
    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: Problem with Model/View

    Yes, I suppose you need two separate models because a model cannot provide different data for different views. Notice that the actual data behind the curtains is still exactly the same, both models are just interfaces for Qt's interview framework.
    J-P Nurmi

  6. The following user says thank you to jpn for this useful post:

    Shawn (28th August 2007)

  7. #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: Problem with Model/View

    Oh, and by the way, there's also an example out there: Simple DOM Model Example
    J-P Nurmi

  8. The following user says thank you to jpn for this useful post:

    Shawn (29th August 2007)

Similar Threads

  1. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  2. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  3. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.