Qt中使用QXmlStreamReader解析读取xml文件,.readNext返回值为1,错误类型为Premature end of document

慎思 2019-06-04 04:32:14
我的xml文件是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<!--paramter setting:-->
<paramters>
<classify>
<R_Param>0</R_Param>
<Atomic_Param>0</Atomic_Param>
<Smooth_Param>0</Smooth_Param>
</classify>
<gray_compos>
<Gray_map_Param>0</Gray_map_Param>
</gray_compos>
</paramters>



读取程序如下:
void ThXsImgProcQt::read_param_xml(QString file_path)
{
QFile xml_file(file_path);
QXmlStreamReader xml_reader;
if (!xml_file.open(QFile::ReadOnly|QFile::Text))
{
return;
}
while ((!xml_reader.atEnd())&&(!xml_reader.hasError()))
{
qint64 line_count = xml_reader.lineNumber();
QXmlStreamReader::TokenType type = xml_reader.readNext();
if (type == 1)
{
QString error_string = xml_reader.errorString();

}

if (type == QXmlStreamReader::StartDocument)
{

}
if (xml_reader.isStartElement()&&xml_reader.name()== this->m_p_wg_tools->m_wg_classify.ui.label_r_param->text())
{
QString string = this->m_p_wg_tools->m_wg_classify.ui.lineEdit_r_param->text();
}



}
if (xml_reader.hasError())
{
//做错误处理
}


}

有哪位指点下哪里出问题了呢
...全文
1631 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
慎思 2019-06-10
  • 打赏
  • 举报
回复
引用 2 楼 hzh_Beyond 的回复:
QXmlStreamReader xml_reader(&file_path);是不是少了初始化这一步。
是的。。。
浮一大白开水 2019-06-05
  • 打赏
  • 举报
回复
QXmlStreamReader xml_reader(&file_path);是不是少了初始化这一步。
慎思 2019-06-05
  • 打赏
  • 举报
回复
帮我自己顶一下
A Brief History of Qt Part I: Basic Qt Chapter 1. Getting Started Hello Qt Making Connections Laying Out Widgets Using the Reference Documentation Chapter 2. Creating Dialogs Subclassing QDialog Signals and Slots in Depth Rapid Dialog Design Shape-Changing Dialogs Dynamic Dialogs Built-in Widget and Dialog Classes Chapter 3. Creating Main Windows Subclassing QMainWindow Creating Menus and Toolbars Setting Up the Status Bar Implementing the File Menu Using Dialogs Storing Settings Multiple Documents Splash Screens Chapter 4. Implementing Application Functionality The Central Widget Subclassing QTableWidget Loading and Saving Implementing the Edit Menu Implementing the Other Menus Subclassing QTableWidgetItem Chapter 5. Creating Custom Widgets Customizing Qt Widgets Subclassing QWidget Integrating Custom Widgets with Qt Designer Double Buffering
Part II: Intermediate Qt Chapter 6. Layout Management Laying Out Widgets on a Form Stacked Layouts Splitters Scrolling Areas Dock Windows and Toolbars Multiple Document Interface Chapter 7. Event Processing Reimplementing Event Handlers Installing Event Filters Staying Responsive during Intensive Processing Chapter 8. 2D Graphics Painting with QPainter Coordinate System Transformations High-Quality Rendering with QImage Item-Based Rendering with Graphics View Printing Chapter 9. Drag and Drop Enabling Drag and Drop Supporting Custom Drag Types Clipboard Handling Chapter 10. Item View Classes Using the Item View Convenience Classes Using Predefined Models Implementing Custom Models Implementing Custom Delegates Chapter 11. Container Classes Sequential Containers Associative Containers Generic Algorithms Strings, Byte Arrays, and Variants Chapter 12. Input/Output Reading and Writing Binary Data Reading and Writing Text Traversing Directories Embedding Resources Inter-Process Communication Chapter 13. Databases Connecting and Querying Viewing Tables Editing Records Using Forms Presenting Data in Tabular Forms Chapter 14. Multithreading Creating Threads Synchronizing Threads Communicating with the Main Thread Using Qt's Classes in Secondary Threads Chapter 15. Networking Writing FTP Clients Writing HTTP Clients Writing TCP Client–Server Applications Sending and Receiving UDP Datagrams Chapter 16. XML Reading XML with QXmlStreamReader Reading XML with DOM Reading XML with SAX Writing XML Chapter 17. Providing Online Help Tooltips, Status Tips, and "What's This?" Help Using a Web Browser to Provide Online Help Using QTextBrowser as a Simple Help Engine Using Qt Assistant for Powerful Online Help
Part III: Advanced Qt Chapter 18. Internationalization Working with Unicode Making Applications Translation-Aware Dynamic Language Switching Translating Applications Chapter 19. Look and Feel Customization Using Qt Style Sheets Subclassing QStyle Chapter 20. 3D Graphics Drawing Using OpenGL Combining OpenGL and QPainter Doing Overlays Using Framebuffer Objects Chapter 21. Creating Plugins Extending Qt with Plugins Making Applications Plugin-Aware Writing Application Plugins Chapter 22. Application Scripting Overview of the ECMAScript Language Extending Qt Applications with Scripts Implementing GUI Extensions Using Scripts Automating Tasks through Scripting Chapter 23. Platform-Specific Features Interfacing with Native APIs Using ActiveX on Windows Handling X11 Session Management Chapter 24. Embedded Programming Getting Started with Qt/Embedded Linux Customizing Qt/Embedded Linux Integrating Qt Applications with Qtopia Using Qtopia APIs
Part IV: Appendixes Appendix A. Obtaining and Installing Qt A Note on Licensing Installing Qt/Windows Installing Qt/Mac Installing Qt/X11 Appendix B. Building Qt Applications Using qmake Using Third-Party Build Tools Appendix C. Introduction to Qt Jambi Getting Started with Qt Jambi Using Qt Jambi in the Eclipse IDE Integrating C++ Components with Qt Jambi Appendix D. Introduction to C++ for Java and C# Programmers Getting Started with C++ Main Language Differences The Standard C++ Library About the Authors Jasmin Blanchette Mark Summerfield Production Index

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧