Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Qt imports xml

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to introduce Qt into xml, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

I. Preface

The last article was responsible for exporting the designed control data to a xml file. This partial article is responsible for importing the exported xml data file and then automatically generating the corresponding controls on the canvas. The built-in xml data parsing function of Qt is very powerful and is encapsulated in QtXml components. One advantage of Qt is that it encapsulates the functions of many major operating system platforms, especially the GUI control, which is worthy of a very large one-stop GUI supermarket. Although the network components are not very powerful, they are more than sufficient to cope with some basic applications. When exporting xml data, attribute lists and values are stored according to xml attributes rather than child nodes, so when parsing, you need to traverse the node's attribute names and values, QDomNamedNodeMap attrs = element.attributes (); then loop out the names and values one by one, QDomNode n = attrs.item (I); QString nodeName = n.nodeName (); QString nodeValue = n.nodeValue ()

Second, the functions realized

Automatically load all the controls in the plug-in file to generate a list, with more than 120 controls by default.

Drag to the canvas to automatically generate the corresponding control, WYSIWYG.

On the right side of the Chinese attribute bar, change the corresponding attributes immediately applied to the corresponding selected controls, intuitive and concise, very suitable for rookies to use.

The original attribute bar text translation mapping mechanism is extremely efficient, and it is very convenient to expand the attribute bar of other languages.

The properties of all controls are automatically extracted and displayed in the right property bar, including the enumerated value drop-down box.

Support manual selection of plug-in files, external import plug-in files.

You can export all control configuration information for the current canvas to a xml file.

You can manually select the xml file to open the control layout and automatically load the control according to the xml file.

Can pull the slider, check the analog data check box, text box input, three ways to generate data to apply all controls.

The control supports eight azimuth pull adjustments, adapts to any resolution, and fine-adjusts the position up and down the keyboard.

Through the serial port acquisition, network acquisition, database collection of three ways to set data.

The code is extremely concise, the comments are very detailed, and can be used as an embryonic form of configuration to expand more functions.

Pure Qt writing, support any Qt version + any compiler + any system.

Third, effect picture

4. The core code void frmMain::openFile (const QString & fileName) {/ / opens the file QFile file (fileName); if (! file.open (QFile::ReadOnly | QFile::Text)) {return;} / / populates the file into the dom container QDomDocument doc; if (! doc.setContent (& file)) {file.close (); return;} file.close () / / first clear the original control QList widgets = ui- > centralwidget- > findChildren (); qDeleteAll (widgets); widgets.clear (); / / first determine whether the root element is correct QDomElement docElem = doc.documentElement (); if (docElem.tagName () = = "canvas") {QDomNode node = docElem.firstChild (); QDomElement element = node.toElement () While (! node.isNull ()) {QString name = element.tagName (); / / Storage coordinates + width and height int x, y, width, height; / / Store other custom control properties QList propertys / / continue if (! name.isEmpty ()) {/ / traverse the attribute name and attribute value of the node QDomNamedNodeMap attrs = element.attributes (); for (int I = 0; I < attrs.count (); iNode +) {QDomNode n = attrs.item (I) QString nodeName = n.nodeName (); QString nodeValue = n.nodeValue (); / / qDebug ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report