0

QStringとしてxmlを生成するために、独自のxmlライターを実装しました。

QXmlStreamWriter としてプライベート メンバー変数を持つクラス「MyXmlWriter」を作成し、パブリック メソッド writeToString() で初期化しようとしました。

宣言ヘッダー ファイル:

class MyXmlWriter {
  public:
    MyXmlWriter();
    ~MyXmlWriter();
    QString writeToString();
  private:
    QXmlStreamWriter writer;
    void writePart();
}

cpp ファイル内:

void MyXmlWriter::writePart() {
   // i want to use the QXmlStreamWriter instance hier
}
QString MyXmlWriter::writeToString(){
   QString result;
   writer(&result); // at this became the error: no match for call to '(QXmlStreamWriter) (QString*)'
   xmlWriter.setAutoFormatting(true);
   // private method called 
   writePart();

   return result;
}

このエラーはビルド時に表示されます: error: no match for call to (QXmlStreamWriter) (QString ) writer(&result); *

QXmlStreamWriter 書き込みがローカル メソッドwriteToString()で宣言されている場合、プライベート メソッドwritePart()でこのライターにアクセスでき ません。メンバー変数「writer」を他のメソッドで使用したいので、ローカル宣言はオプションではありません。 .

4

1 に答える 1