hello i am using the following program to display the qtreewidget.
main.cpp
include
include "qdomsimple.h"
include
include "qdomsimple.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QStringList filelist;
filelist.push_back("C:\department1.xml");
filelist.push_back("C:\department2.xml");
filelist.push_back("C:\department3.xml");
QDOMSimple w(filelist);
w.resize(260,200);
w.show();
return a.exec();
}
qdomsimple.cpp
include "qdomsimple.h"
include
include
QDOMSimple::QDOMSimple(QStringList strlst,QWidget *parent)
: QWidget(parent)
{
k=0;
// DOM document
QDomDocument doc("title");
QStringList headerlabels;
headerlabels.push_back("Chemistry");
headerlabels.push_back("Mechanical");
headerlabels.push_back("IT");
m_tree = new QTreeWidget( this );
m_tree->setColumnCount(3);
m_tree->setHeaderLabels(headerlabels);
QStringList::iterator it;
for(it=strlst.begin();it<strlst.end();it++)
{
QFile file(*it);
if ( file.open( QIODevice::ReadOnly | QIODevice::Text ))
{
// The tree view to be filled with xml data
// (m_tree is a class member variable)
// Creating the DOM tree
doc.setContent( &file );
file.close();
// Root of the document
QDomElement root = doc.documentElement();
// Taking the first child node of the root
QDomNode child = root.firstChild();
// Setting the root as the header of the tree
//QTreeWidgetItem* header = new QTreeWidgetItem;
//header->setText(k,root.nodeName());
//m_tree->setHeaderItem(header);
// Parse until the end of document
while (!child.isNull())
{
//Convert a DOM node to DOM element
QDomElement element = child.toElement();
//Parse only if the node is a really an element
if (!element.isNull())
{
//Parse the element recursively
parseElement( element,0);
//Go to the next sibling
child = child.nextSiblingElement();
}
}
//m_tree->setGeometry( QApplication::desktop()->availableGeometry() );
//setGeometry( QApplication::desktop()->availableGeometry() );
}
k++;
}
}
void QDOMSimple::parseElement( QDomElement& aElement, QTreeWidgetItem *aParentItem )
{
// A map of all attributes of an element
QDomNamedNodeMap attrMap = aElement.attributes();
// List all attributes
QStringList attrList;
for ( int i = 0; i < attrMap.count(); i++ )
{
// Attribute name
//QString attr = attrMap.item( i ).nodeName();
//attr.append( "-" );
/* Attribute value
QString attr;
attr.append( attrMap.item( i ).nodeValue() );*/
//attrList.append( attr );
attrList.append(attrMap.item( i).nodeValue());
}
QTreeWidgetItem* item;
// Create a new view item for elements having child nodes
if (aParentItem)
{
item = new QTreeWidgetItem(aParentItem);
}
// Create a new view item for elements without child nodes
else
{
item = new QTreeWidgetItem( m_tree );
}
//Set tag name and the text
QString tagNText;
tagNText.append( aElement.tagName() );
//tagNText.append( "------" );
//tagNText.append( aElement.text() );
item->setText(0, tagNText );
// Append attributes to the element node of the tree
for ( int i = 0; i < attrList.count(); i++ )
{
QTreeWidgetItem* attrItem = new QTreeWidgetItem( item );
attrItem->setText(0, attrList[i] );
}
// Repeat the process recursively for child elements
QDomElement child = aElement.firstChildElement();
while (!child.isNull())
{
parseElement( child, item );
child = child.nextSiblingElement();
}
}
QDOMSimple::~QDOMSimple()
{
}
for this i got the qtreewidget like this
+file1
+file2
+file3
but actual wanted output is
+file1 +file2 +file3
i don't know how to do it.Thanks in advance