本文整理汇总了C++中QDomDocument::hasChildNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ QDomDocument::hasChildNodes方法的具体用法?C++ QDomDocument::hasChildNodes怎么用?C++ QDomDocument::hasChildNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDomDocument
的用法示例。
在下文中一共展示了QDomDocument::hasChildNodes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hasChildNodes
bool QDomDocumentProto::hasChildNodes() const
{
QDomDocument *item = qscriptvalue_cast<QDomDocument*>(thisObject());
if (item)
return item->hasChildNodes();
return false;
}
示例2: arg
// Convenience to create a Dom Widget from widget box xml code.
DomUI *QDesignerWidgetBox::xmlToUi(const QString &name, const QString &xml, bool insertFakeTopLevel, QString *errorMessage)
{
QDomDocument doc;
int errorLine, errorColumn;
if (!doc.setContent(xml, errorMessage, &errorLine, &errorColumn)) {
*errorMessage = QObject::tr("A parse error occurred at line %1, column %2 of the XML code specified for the widget %3: %4\n%5").
arg(errorLine).arg(errorColumn).arg(name).arg(*errorMessage).arg(xml);
return 0;
}
if (!doc.hasChildNodes()) {
*errorMessage = QObject::tr("The XML code specified for the widget %1 does not contain any widget elements.\n%2").arg(name).arg(xml);
return 0;
}
QDomElement rootElement = doc.firstChildElement();
const QString rootNode = rootElement.nodeName();
const QString widgetTag = QLatin1String("widget");
if (rootNode == widgetTag) { // 4.3 legacy ,wrap into DomUI
DomUI *rc = new DomUI;
DomWidget *widget = new DomWidget;
widget->read(rootElement);
if (insertFakeTopLevel) {
DomWidget *fakeTopLevel = new DomWidget;
QList<DomWidget *> children;
children.push_back(widget);
fakeTopLevel->setElementWidget(children);
rc->setElementWidget(fakeTopLevel);
} else {
rc->setElementWidget(widget);
}
return rc;
}
if (rootNode == QLatin1String("ui")) { // 4.4
QDomElement widgetChild = rootElement.firstChildElement(widgetTag);
if (widgetChild.isNull()) {
*errorMessage = QObject::tr("The XML code specified for the widget %1 does not contain valid widget element\n%2").arg(name).arg(xml);
return 0;
}
if (insertFakeTopLevel) {
QDomElement fakeTopLevel = doc.createElement(widgetTag);
rootElement.replaceChild(fakeTopLevel, widgetChild);
fakeTopLevel.appendChild(widgetChild);
}
DomUI *rc = new DomUI;
rc->read(rootElement);
return rc;
}
*errorMessage = QObject::tr("The XML code specified for the widget %1 contains an invalid root element %2.\n%3").arg(name).arg(rootNode).arg(xml);
return 0;
}
示例3: setShowDockIcon
void QNapiConfig::setShowDockIcon(bool show)
{
QString infoPlistPath = QFileInfo(QApplication::applicationDirPath() + "/../Info.plist").canonicalFilePath();
QFile plistFile(infoPlistPath);
QDomDocument doc;
if(!doc.setContent(&plistFile) || !doc.hasChildNodes())
return;
QDomNodeList nodes = doc.childNodes();
QDomNode node;
int i;
for(i = 0; i < nodes.size(); ++i)
{
node = nodes.at(i);
if(node.nodeName() == "plist")
break;
}
if((i == nodes.size()) || !node.hasChildNodes())
return;
nodes = node.childNodes();
for(i = 0; i < nodes.size(); ++i)
{
node = nodes.at(i);
if(node.nodeName() == "dict")
break;
}
if((i == nodes.size()) || !node.hasChildNodes())
return;
nodes = node.childNodes();
for(i = 0; i < nodes.size(); ++i)
{
node = nodes.at(i);
QString subText;
if(node.hasChildNodes())
{
subText = node.childNodes().at(0).toText().data();
}
if(subText == "LSUIElement")
break;
}
if(i >= nodes.size())
return;
node = node.nextSibling();
node.toElement().setTagName(show ? "false" : "true");
QString modifiedContent = doc.toString(4);
plistFile.close();
if(!plistFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
return;
QTextStream plistStream(&plistFile);
plistStream << modifiedContent;
plistFile.close();
}
示例4: showDockIcon
bool QNapiConfig::showDockIcon()
{
const bool show_default = true;
QString infoPlistPath = QFileInfo(QApplication::applicationDirPath() + "/../Info.plist").canonicalFilePath();
QFile plistFile(infoPlistPath);
QDomDocument doc;
if(!doc.setContent(&plistFile))
return show_default;
if(!doc.hasChildNodes())
return show_default;
QDomNodeList nodes = doc.childNodes();
QDomNode node;
int i;
for(i = 0; i < nodes.size(); ++i)
{
node = nodes.at(i);
if(node.nodeName() == "plist")
break;
}
if(i == nodes.size())
return show_default;
if(!node.hasChildNodes())
return show_default;
nodes = node.childNodes();
for(i = 0; i < nodes.size(); ++i)
{
node = nodes.at(i);
if(node.nodeName() == "dict")
break;
}
if(i == nodes.size())
return show_default;
if(!node.hasChildNodes())
return show_default;
nodes = node.childNodes();
for(i = 0; i < nodes.size(); ++i)
{
node = nodes.at(i);
QString subText;
if(node.hasChildNodes())
{
subText = node.childNodes().at(0).toText().data();
}
if(subText == "LSUIElement")
break;
}
if(i < nodes.size())
{
node = node.nextSibling();
return (node.nodeName() != "true");
}
return show_default;
}