没有匹配函数来调用'QDomDocument :: createElement( )”

问题描述 投票:0回答:1

我目前正在尝试将一些QLineEdits的值放入XML文档中。我为此使用QDom。这是我的代码:

void MainWindow::writeSysConf(const QString &arg1){
QFileDialog fdExport;

QString filename = fdExport.getSaveFileName(
        this,
        tr("SysConf-Konfig speichern"),
            arg1,
        tr("Konfigurationsdatei (*.xml)") );

if( !filename.isNull()) {
    QFile::remove(filename);
    if ( !filename.endsWith(".xml", Qt::CaseInsensitive))
        filename += ".xml";
    QFile file(filename);
    file.open(QIODevice::WriteOnly | QIODevice::Text);
    QTextStream outPut(&file);
    QDomDocument xmlDocument;

    QDomElement sysConfigElement = xmlDocument.createElement("SYSTEMCONFIGURATION");
    QDomElement calibElement = xmlDocument.createElement("CALIB");
    QDomElement crescendoElement = xmlDocument.createElement("CRESCENDO");
    QDomElement swellsElement = xmlDocument.createElement("SWELLS");
    sysConfigElement.appendChild(calibElement);
    calibElement.appendChild(crescendoElement);

    QDomNode minNode = xmlDocument.createElement(ui->lineEdit_2->text);
    QDomNode maxNode = xmlDocument.createElement(ui->lineEdit_3->text);
    QDomNode stepsNode = xmlDocument.createElement(ui->lineEdit_4->text);
    QDomNode updateMsNode = xmlDocument.createElement(ui->lineEdit_5->text);

    crescendoElement.appendChild(minNode);
    crescendoElement.appendChild(maxNode);
    crescendoElement.appendChild(stepsNode);
    crescendoElement.appendChild(updateMsNode);

    calibElement.appendChild(swellsElement);

    xmlDocument.appendChild(sysConfigElement);
    outPut << xmlDocument.toString(4);
}

}

但是,在这四行:

QDomNode minNode = xmlDocument.createElement(ui->lineEdit_2->text);
QDomNode maxNode = xmlDocument.createElement(ui->lineEdit_3->text);
QDomNode stepsNode = xmlDocument.createElement(ui->lineEdit_4->text);
QDomNode updateMsNode = xmlDocument.createElement(ui->lineEdit_5->text);

它说我会尝试使用未解析的重载函数类型将其放入我的QDomNodes中。但是,据我所知,QLineEdits返回一个QString。那么问题出在哪里?

c++ qt qtxml qdomdocument
1个回答
0
投票

固定它。您只需要在ui-> lineEdit->文本后面添加一个(),因为它是一个函数。所以我的方式应该是这样的:

QDomNode minNode = xmlDocument.createElement(ui->lineEdit_2->text());
QDomNode maxNode = xmlDocument.createElement(ui->lineEdit_3->text());
QDomNode stepsNode = xmlDocument.createElement(ui->lineEdit_4->text());
QDomNode updateMsNode = xmlDocument.createElement(ui->lineEdit_5->text());
© www.soinside.com 2019 - 2024. All rights reserved.