Results 1 to 4 of 4

Thread: xml - get number of columns

  1. #1
    Join Date
    Sep 2006
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question xml - get number of columns

    My XML looks like this:
    Qt Code:
    1. <row>
    2. <column name="name">c1</column>
    3. <column name="address">c2</column>
    4. </row>
    5. <row>
    6. <column name="name">c11</column>
    7. <column name="address">c22</column>
    8. </row>
    To copy to clipboard, switch view to plain text mode 

    Is there any easy way to get the numbers of columns in a row?
    btw: The number of columns is in all rows the same.

  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: xml - get number of columns

    I don't know if I understand the problem correctly, but how about this:

    Qt Code:
    1. QDomElement rowelement;
    2. int columncount = 0;
    3. for(QDomElement colelement = rowelement.firstChildElement("column");
    4. !colelement.isNull();
    5. colelement = colelement.nextSiblingElement("column")
    6. )
    7. columncount++;
    8. qDebug("Column count is %d", columncount);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    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: xml - get number of columns

    Take a look at QtXml module. A few XML examples are shipped with Qt, and there are short pieces of example code in the docs as well: QDomDocument, QDomElement..
    J-P Nurmi

  4. #4
    Join Date
    Sep 2006
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: xml - get number of columns

    int columns = xml_doc.documentElement().firstChild().firstChildE lement().childNodes().count();

Similar Threads

  1. QPopupMenu with 2 columns
    By raphaelf in forum Qt Programming
    Replies: 6
    Last Post: 11th October 2006, 10:06
  2. Maximize columns on QTableWidget
    By marcelrc in forum Newbie
    Replies: 1
    Last Post: 21st May 2006, 15:34
  3. Replies: 6
    Last Post: 5th March 2006, 21:05
  4. QTableView number of rows and scrollbar issue
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2006, 06:55
  5. Changing the order of columns in QTreeView
    By johnny_sparx in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 00:00

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.