⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saxhandler.cpp

📁 QT4 gui programming的随书光盘
💻 CPP
字号:
#include <QtGui>#include <iostream>#include "saxhandler.h"SaxHandler::SaxHandler(QTreeWidget *tree){    treeWidget = tree;}bool SaxHandler::readFile(const QString &fileName){    currentItem = 0;    QFile file(fileName);    QXmlInputSource inputSource(&file);    QXmlSimpleReader reader;    reader.setContentHandler(this);    reader.setErrorHandler(this);    return reader.parse(inputSource);}bool SaxHandler::startElement(const QString & /* namespaceURI */,                              const QString & /* localName */,                              const QString &qName,                              const QXmlAttributes &attributes){    if (qName == "entry") {        currentItem = new QTreeWidgetItem(currentItem ?                currentItem : treeWidget->invisibleRootItem());        currentItem->setText(0, attributes.value("term"));    } else if (qName == "page") {        currentText.clear();    }    return true;}bool SaxHandler::characters(const QString &str){    currentText += str;    return true;}bool SaxHandler::endElement(const QString & /* namespaceURI */,                            const QString & /* localName */,                            const QString &qName){    if (qName == "entry") {        currentItem = currentItem->parent();    } else if (qName == "page") {        if (currentItem) {            QString allPages = currentItem->text(1);            if (!allPages.isEmpty())                allPages += ", ";            allPages += currentText;            currentItem->setText(1, allPages);        }    }    return true;}bool SaxHandler::fatalError(const QXmlParseException &exception){    std::cerr << "Parse error at line " << exception.lineNumber()              << ", " << "column " << exception.columnNumber() << ": "              << qPrintable(exception.message()) << std::endl;    return false;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -