Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    C2061 - Syntax error

    General and Desktop
    3
    9
    4227
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      MichelleK last edited by

      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 gui

      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

      TARGET = DomTreeWithPart
      TEMPLATE = app

      SOURCES += main.cpp
      mainwindow.cpp
      OutlineTree.cpp

      HEADERS += mainwindow.h

      FORMS += mainwindow.ui
      @

      Any thoughts or suggestions would be greatly appreciated.

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        You need to include QListViewItem, too.

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • M
          MichelleK last edited by

          I did try that. It said there was no such file.

          1 Reply Last reply Reply Quote 0
          • sierdzio
            sierdzio Moderators last edited by

            Oh sorry, I've mistaken that with QListWidgetItem, which does exist. Your example code might be wrong, then.

            (Z(:^

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply Reply Quote 0
              • M
                MichelleK last edited by

                I am using Qt 5.0.2. So, are you saying that QListViewItem is no longer valid in this version? If so, what would I use instead?

                1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  QListViewItem was already no longer valid in Qt 4.

                  Could you explain what you want to achieve so I can better help you ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply Reply Quote 0
                  • M
                    MichelleK last edited by

                    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.

                    1 Reply Last reply Reply Quote 0
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      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

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post