0

我目前正在尝试将一些 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。那么问题出在哪里?

4

1 回答 1

0

解决它。您只需要在 ui->lineEdit->text 后面添加一个 () ,因为它是一个函数。所以我的以正确的方式看起来像这样:

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());
于 2014-03-27T16:39:22.817 回答