用Qt讀取xml檔案,程式執行到 if(!doc.setContent(&file)) 時候出錯,xmldoc.setcontent

來源:互聯網
上載者:User

用Qt讀取xml檔案,程式執行到 if(!doc.setContent(&file)) 時候出錯,xmldoc.setcontent

看霍亞飛的那本<Qt Creator快速入門>,然後就照著寫那個DOM方式讀取xml檔案的例子出這樣的錯誤。

一開始大家都以為自己的路徑會有問題,其實在之前open的時候沒問題,怎麼可能到後面這裡才出問題呢?(自己也在這裡繞了很多彎彎)

通過其他方式瞭解這個函數的原理,其實就是建立一個樹,將xml格式的資料儲存到一個樹一樣結構的doc裡面去。也就是說,我們在建立這個樹的時候出錯了,定位一下就知道自己的XML檔案是不是錯了。

換一個xml,網上下下吧,比較一下發現,原來第一行的<?xml version = "1.0" encoding = "UTF-8"?>中的問號兩邊不能有空格!

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.