C2061 - Syntax error
-
I am new at QT, so I apologize if this is an easy question, but I have typed in an example that I found that uses QListViewItem and for some reason it can not find it, even though I am including qlistview.h. Here is the header where I am getting the error:
@
#include <QMainWindow>
#include <qlistview.h>
#include <QtXml\QDomDocument>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);
};
@And here is the .pro file, in case you find it useful:
@
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = DomTreeWithPart
TEMPLATE = appSOURCES += main.cpp
mainwindow.cpp
OutlineTree.cppHEADERS += mainwindow.h
FORMS += mainwindow.ui
@Any thoughts or suggestions would be greatly appreciated.
-
You need to include QListViewItem, too.
-
Oh sorry, I've mistaken that with QListWidgetItem, which does exist. Your example code might be wrong, then.
-
Hi,
QListViewItem is from Qt 3, you should either update your code to use the Qt 4/5 classes or use Qt3Support but it's not a good idea since you seem to learn Qt.
As a side note it's Qt, QT stands for Apple's QuickTime :)
Hope it helps
-
QListViewItem was already no longer valid in Qt 4.
Could you explain what you want to achieve so I can better help you ?
-
I was trying to read in an XML file using DOM and create a tree. I found an example online (evidently an old one) and tried to implement it for my file. The code in the class that is supposed to do everything looks like this:
@
OutlineTree::OutlineTree( const QString fileName, QWidget *parent, const char *name)
:QListView( parent, name)
{
QFile partFile("c:/qt experiments/database/parts/theFile.xml");
if (!partFile.open(QIODevice::ReadOnly)) {
QMessageBox::critical(0, tr("Critical Error"), tr("Parsing error for file"));
partFile.close();
return;
}
partFile.close();//Get the header information from the DOM QDomElement root = domTree.documentElement(); QDomNode node; node = root.firstChild(); while ( !node.isNull()) { if (node.isElement() && node.nodeName() == "PART") { QDomElement part = node.toElement(); getHeaderInformation(part); break; } node = node.nextSibling(); } //Create the tree view out of the DOM node = root.firstChild(); while (!node.isNull()) { if (node.isElement() && node.nodeName() == "PLY") { QDomElement plys = node.toElement(); buildTree(0, plys); break; } node = node.nextSibling(); }
}
OutlineTree::~OutlineTree()
{}
void OutlineTree::getHeaderInformation(const QDomElement &header)
{
//no children only attributes
}void OutlineTree::buildTree(QListViewItem * parentItem, const QDomElement &parentElement)
{
QListViewItem * thisItem = 0;
QDomNode node = parentElement.firstChild();
while (!node.isNull()) {
//add a new list view item for the outline
if (parentItem == 0) {
if (node.isElement() && node,nodeName() == "PLY") {
thisItem = new QListViewItem(this, thisItem);
} else {
thisItem = new QListViewItem(parentItem, thisItem);
}
thisItem->setText(0, node.toElement().attribute("NAME"));
//recursive build of the tree
buildTree(thisItem, node.toElement());
}
node = node.nextSibling();
}
}
@Maybe I should just find a more up-to-date example.
-
Then I would recommend the reading of Qt 5 doc's about QDomDocument and have look at the DOM Bookmark example. It covers exactly what you want