A method, apparatus, equipment, medium, and product for bidirectional data conversion between TOML and Qt.

CN122569989APending Publication Date: 2026-08-14四川腾盾科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-04-16
Publication Date
2026-08-14

AI Technical Summary

Technical Problem

[0005]本发明旨在提供一种TOML与Qt数据双向转换方法、装置、设备、介质及产品,以解决基于TOML类型和Qt类型的数据的应用研发时,开发效率低和代码维护成本高的问题

Benefits of technology

[0017]上述第二方面至第五方面的有益效果参考第一方面的对应描述,不再赘述。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122569989A_ABST
    Figure CN122569989A_ABST
Patent Text Reader

Abstract

This invention belongs to the field of data processing technology, and provides a method, apparatus, device, medium, and product for bidirectional conversion between TOML and Qt data. This method aims to improve the development efficiency of configuration management units in Qt-based applications and reduce code maintenance costs. The method uses a first preset mapping rule to convert TOML standard type data into corresponding Qt meta type data, converting the target TOML file into a corresponding target Qt file, and returning the target Qt file to the application layer. Then, using a second preset mapping rule to convert Qt meta type data into corresponding TOML standard type data, the method converts the target modified Qt file into a corresponding target modified TOML file, and stores the target modified TOML file in an external storage layer. This improves the development efficiency of configuration management units in Qt-based applications and reduces code maintenance costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and more specifically, to a method, apparatus, device, medium, and product for bidirectional conversion of TOML and Qt data. Background Technology

[0002] The Qt framework is a cross-platform C++ graphical user interface application development framework widely used in industrial control, desktop applications, and embedded development. In software configuration management, JSON and XML are data formats that the Qt framework natively supports well.

[0003] With the development of software engineering, TOML (Tom's Obvious, Minimal Language) has gradually become one of the mainstream choices for software configuration files due to its clear semantics, rigorous syntax, and ease of human reading.

[0004] However, the Qt framework does not yet have built-in direct support for the TOML format. Existing solutions mostly involve using third-party C++ TOML parsing libraries. These third-party libraries require users to manually convert between STL and Qt types, and they cannot directly utilize the Qt framework to manage configuration data uniformly, significantly reducing development efficiency and increasing code maintenance costs. Summary of the Invention

[0005] This invention aims to provide a method, apparatus, device, medium, and product for bidirectional conversion between TOML and Qt data, in order to solve the problems of low development efficiency and high code maintenance costs in the development of applications based on TOML and Qt data.

[0006] Firstly, this application provides a method for bidirectional data conversion between TOML and Qt, including: In response to an application layer initiating a read action, the target TOML file to be read is obtained; wherein, the target TOML file is used to indicate the TOML configuration file that the application layer wants to access; The target TOML file is converted into the corresponding target Qt file using the first preset mapping rule; wherein, the first preset mapping rule is used to convert data of the TOML standard type into data of the corresponding Qt meta type. Return the target Qt file to the application layer; When a write operation is initiated by the application layer, the target modified Qt file is obtained; the target modified Qt file is used to indicate the Qt configuration file after being modified by the application layer. The target modified Qt file is converted into the corresponding target modified TOML file using the second preset mapping rule; wherein, the second preset mapping rule is used to convert Qt meta type data into corresponding TOML standard type data; The target modified TOML file is stored in an external storage layer.

[0007] The technical solution provided in this application brings at least the following beneficial effects: When the application layer initiates a read action, it obtains the target TOML file indicating the TOML configuration file the application layer wants to access. Then, using a first preset mapping rule to convert data of the TOML standard type into the corresponding Qt meta type data, it converts the target TOML file into a corresponding target Qt file and returns the target Qt file to the application layer. When the application layer initiates a write action, it obtains the target modified Qt file indicating the Qt configuration file modified by the application layer. Using a second preset mapping rule to convert data of the Qt meta type into the corresponding TOML standard type data, it converts the target modified Qt file into a corresponding target modified TOML file and stores the target modified TOML file in an external storage layer. Thus, by combining the first and second preset mapping rules, this application achieves seamless integration between TOML data and the core Qt data structure. Developers do not need to worry about the underlying parsing details and type conversions; they can read and write TOML files as easily as manipulating JSON, thereby significantly improving the development efficiency of configuration management units in Qt-based applications and reducing code maintenance costs.

[0008] One possible implementation, before converting the target TOML file to the corresponding target Qt file using the first preset mapping rule, also includes: Perform path validity verification on the target TOML file; the path validity verification is used to check whether the target TOML file exists in the external storage layer. In response to the successful path validation for the target to read the TOML file, permission verification is performed on the target to read the TOML file; the permission verification is used to check whether the user corresponding to the application layer has read permission to read the target TOML file. In response to the successful permission verification of the target TOML file, the target TOML file is converted into the corresponding target Qt file according to the first preset mapping rule.

[0009] One possible implementation involves converting the target TOML file into a corresponding target Qt file using a first preset mapping rule, including: Load the contents of the target TOML file as the target root node; Based on the type attribute of the target root node and the first preset mapping rule, the target root node is traversed to obtain the corresponding target Qt file.

[0010] One possible implementation involves traversing the target root node based on its type attribute and a first preset mapping rule, including: When the type attribute of the target root node is TOML table type, the content in the target root node is converted and inserted into the corresponding QVariantHash object through the first read sub-rule of the first preset mapping rule; wherein, the first read sub-rule is used to indicate that the content data of TOML table type is mapped to the corresponding QVariantHash object; When the type attribute of the target root node is a TOML array type, the content in the target root node is converted and inserted into the corresponding QVariantList object through the second read sub-rule of the first preset mapping rule; wherein, the second read sub-rule is used to indicate that the content data of the TOML array type is mapped to the corresponding QVariantList object; When the type attribute of the target root node is time or date, the content in the target root node is converted to the corresponding Qt time object through the third read sub-rule of the first preset mapping rule; wherein, the third read sub-rule is used to indicate that the content data of the TOML array type is mapped to the corresponding Qt time object; Mark the QVariantHash object, QVariantList object, and Qt time object as targets to read the Qt file.

[0011] One possible implementation involves converting the target modified Qt file into a corresponding target modified TOML file using a second preset mapping rule, including: Modify the Qt file based on the target and create a corresponding blank root-level TOML table object; Based on the type attributes of each Qt data in the target modified Qt file and the second preset mapping rule, the content data in the target modified Qt file is traversed to obtain the corresponding child TOML objects; Insert the corresponding child TOML objects into the blank root TOML table object to obtain the target modified TOML file.

[0012] One possible implementation involves iterating through the content data in the target modified Qt file based on the type attributes of each Qt data in the container and a second preset mapping rule to obtain the corresponding child TOML objects, including: When the type attribute of Qt data is QVariantHash or QVariantMap, the content of the target modified Qt file is converted to the corresponding child TOML table object through the first write sub-rule of the second preset mapping rule; wherein, the first write sub-rule is used to indicate that the content data of QVariantHash object or QVariantMap object is mapped to the corresponding child TOML table object; When the type attribute of Qt data is QVariantList, the content of the target modified Qt file is converted to the corresponding child TOML array object through the second write sub-rule of the second preset mapping rule; wherein, the second write sub-rule is used to indicate that the content data of the QVariantList object is mapped to the corresponding child TOML array object; When the type attribute of Qt data is QDate, QTime, or QDateTime, the content of the target modified Qt file is converted to the corresponding child TOML date and time object through the third write sub-rule of the second preset mapping rule; wherein, the third write sub-rule is used to indicate that the content data of QDate, QTime, or QDateTime object is mapped to the corresponding child TOML date and time object.

[0013] Secondly, this application provides a bidirectional data conversion device between TOML and Qt, comprising: The first acquisition module is used to acquire the target TOML file to be read in response to the application layer initiating a read action; wherein, the target TOML file is used to indicate the TOML configuration file that the application layer wants to access; The first processing module is used to convert a target TOML file into a corresponding target Qt file using a first preset mapping rule; wherein, the first preset mapping rule is used to convert data of the TOML standard type into data of the corresponding Qt meta type. The first processing module is also used to return the target read Qt file to the application layer; The second acquisition module is used to acquire the target modified Qt file in response to the application layer initiating a write action; wherein, the target modified Qt file is used to indicate the Qt configuration file after being modified by the application layer; The second processing module is used to convert the target modified Qt file into the corresponding target modified TOML file according to the second preset mapping rule; wherein, the second preset mapping rule is used to convert Qt meta type data into corresponding TOML standard type data; The second processing module is also used to store the target modified TOML file to an external storage layer.

[0014] Thirdly, this application provides an electronic device comprising: a processor and a memory; the memory storing processor-executable instructions; when the processor is configured to execute the instructions, causing the electronic device to implement the method of the first aspect described above.

[0015] Fourthly, this application provides a computer-readable storage medium comprising: computer software instructions; which, when executed in an electronic device, cause the electronic device to implement the method described in the first aspect.

[0016] Fifthly, this application provides a computer program product comprising a computer program that, when run on an electronic device, causes the electronic device to perform the method described in the first aspect.

[0017] The beneficial effects of the second to fifth aspects mentioned above are described in the corresponding description of the first aspect and will not be repeated here. Attached Figure Description

[0018] Figure 1 A flowchart illustrating a method for bidirectional data conversion between TOML and Qt provided in an embodiment of this application; Figure 2 A logic flowchart for the reading stage provided in this application embodiment; Figure 3 A logic flowchart of the writing stage is provided for an embodiment of this application; Figure 4 A schematic diagram of the composition of a TOML to Qt bidirectional data conversion device provided in this application embodiment; Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0019] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three relationships. For example, A and / or B can represent three situations: A exists alone, A and B exist simultaneously, and B exists alone.

[0020] Furthermore, the terms "comprising" and "having," and any variations thereof, used in the description of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the steps or units listed, but may optionally include other steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus.

[0021] It should be noted that in the embodiments of this application, the words "exemplary" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of the words "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.

[0022] In the description of this application, unless otherwise stated, "a plurality of" means two or more.

[0023] The Qt framework, a cross-platform C++ graphical user interface application development framework widely used in industrial control, desktop applications, and embedded development, boasts a powerful meta-object system and a rich set of data container classes (such as QVariant, QHash, and QList). In software configuration management, JSON and XML are data formats natively supported by Qt, allowing developers to easily perform read and write operations using the QJsonDocument or QDomDocument classes.

[0024] However, the Qt framework does not yet have built-in direct support for the TOML format. Existing solutions mostly involve using third-party C++ TOML parsing libraries (such as tomlplusplus). These third-party libraries are typically based on the C++ Standard Template Library (STL) and heavily utilize std::string, std::vector, and standard iterators. This forces Qt developers to write tedious "glue code" to manually convert between STL and Qt types, and they cannot directly utilize Qt's QVariant mechanism to uniformly manage configuration data, significantly reducing development efficiency and increasing code maintenance costs.

[0025] To address the aforementioned technical problems, this application provides a method, apparatus, device, medium, and product for bidirectional conversion between TOML and Qt data. In response to a read action initiated by the application layer, the application layer obtains a target TOML file indicating the desired TOML configuration file. Then, using a first preset mapping rule to convert data of standard TOML types to corresponding Qt metatypes, the target TOML file is converted into a corresponding target Qt file, which is then returned to the application layer. In response to a write action initiated by the application layer, the application layer obtains a target modified Qt file indicating the modified Qt configuration file. Using a second preset mapping rule to convert data of Qt metatypes to corresponding TOML standard types, the target modified Qt file is converted into a corresponding target modified TOML file, which is then stored in an external storage layer. Thus, by combining the first and second preset mapping rules, this application achieves seamless integration between TOML data and Qt core data structures. Developers do not need to concern themselves with underlying parsing details and type conversions; they can read and write TOML files as easily as manipulating JSON, significantly improving the development efficiency of configuration management modules in Qt applications and reducing code maintenance costs.

[0026] The following is a detailed description of a method for bidirectional conversion between TOML and Qt data provided in the embodiments of this application, with reference to the accompanying drawings.

[0027] Figure 1 This is a flowchart illustrating a method for bidirectional data conversion between TOML and Qt, provided in an embodiment of this application. Figure 2 This is a logic flowchart of the reading stage provided in an embodiment of this application. Figure 3 This is a logic flowchart illustrating a write phase as provided in an embodiment of this application. (In conjunction with...) Figure 1 , Figure 2 and Figure 3 The following describes the bidirectional data conversion method between TOML and Qt provided in the embodiments of this application: S101. In response to the application layer initiating a read action, obtain the target TOML file to be read.

[0028] The target reads the TOML file to indicate the TOML configuration file that the application layer wants to access.

[0029] In one possible implementation, after obtaining the target read TOML file, the path validity verification is performed on the target read TOML file; wherein, the path validity verification is used to verify whether the target read TOML file exists in the external storage layer.

[0030] Furthermore, in response to the successful path validity verification of the target TOML file, permission verification is performed on the target TOML file; wherein, permission verification is used to verify whether the user corresponding to the application layer has read permission to read the target TOML file.

[0031] Furthermore, in response to the successful permission verification of the target TOML file, the target TOML file is converted into the corresponding target Qt file according to the first preset mapping rule.

[0032] Specifically, when the path validity verification or permission verification fails, a prompt message is generated and returned to the application layer to remind the user corresponding to the application layer to re-instruct the application layer to initiate the read action.

[0033] As an example, during the system initialization phase, a middleware class inheriting from QObject (e.g., named QTomlplusplus) is constructed. The TOML-Qt bidirectional data conversion method provided in this application is applied to the aforementioned middleware. This middleware integrates an underlying TOML parsing engine and pre-defines a complete type mapping table. Subsequent first and second pre-defined mapping rules are established based on this type mapping table. The type mapping table defines a one-to-one correspondence between TOML standard types (such as Table, Array, String, Integer, Float, Boolean, Date / Time) and Qt metatypes (such as QVariantHash, QVariantList, QString, LongLong, Double, Bool, QDate / QTime).

[0034] S102. Using the first preset mapping rule, the target TOML file is converted into the corresponding target Qt file.

[0035] In one possible implementation, the target reads the contents of the TOML file and loads them as the target root node.

[0036] In one possible implementation, the target root node is traversed based on its type attribute and a first preset mapping rule to obtain the corresponding target Qt file.

[0037] As an example, when the application layer initiates a read request, the middleware, after verifying the validity of the target Qt file's path and read permissions, calls the underlying parsing function to load the target Qt file content into a root node object in memory. Subsequently, a recursive scanning algorithm performs a depth-first traversal of the target root node. During the traversal, the type attribute of the current node is checked in real time.

[0038] Furthermore, the traversal of the target root node based on the type attribute of the target root node and the first preset mapping rule is explained in detail below: When the type attribute of the target root node is TOML table type, the content in the target root node is converted and inserted into the corresponding QVariantHash object through the first read sub-rule of the first preset mapping rule; wherein, the first read sub-rule is used to indicate that the content data of TOML table type is mapped to the corresponding QVariantHash object.

[0039] When the type attribute of the target root node is a TOML array type, the content in the target root node is converted and inserted into the corresponding QVariantList object through the second reading sub-rule of the first preset mapping rule; wherein, the second reading sub-rule is used to indicate that the content data of the TOML array type is mapped to the corresponding QVariantList object.

[0040] When the type attribute of the target root node is time or date, the content in the target root node is converted to the corresponding Qt time object through the third read sub-rule of the first preset mapping rule; wherein, the third read sub-rule is used to indicate that the content data of the TOML array type is mapped to the corresponding Qt time object.

[0041] Specifically, combined Figure 2 As shown, when the current node is detected to be of type TOML (Table), i.e., a table structure, a QVariantHash object is instantiated, i.e., a Qt hash container is initialized. Then, based on the first read sub-rule, each key-value pair in the type mapping table is traversed, the key is converted to a QString type, and the node conversion function is recursively called on the value part. The return value of the recursive call is inserted into the aforementioned QVariantHash object, i.e., inserted into the Qt hash container, thus replicating the hierarchical structure until the traversal is complete.

[0042] When the current node is detected to be a TOML array (Array) type, i.e., an array structure, a QVariantList object is instantiated, i.e., the Qt list container is initialized. Based on the second reading sub-rule, each element in the array (key-value pair) is traversed sequentially. Based on the type mapping table, a conversion operation is recursively performed on each element, and the result is appended to the QVariantList (Qt list container).

[0043] When the current node is detected to be of time or date type, the year, month, day, hour, minute, second, and millisecond data stored in the TOML node are read based on the third read sub-rule. The constructors of the QDate, QTime, or QDateTime classes in the Qt framework are then called to construct a standard Qt time object. This approach avoids the subsequent parsing difficulties caused by simply treating it as a string.

[0044] For basic data types such as integers, floating-point numbers, booleans, and strings, the values ​​are extracted directly from the underlying library's interface based on the fourth read sub-rule, and then encapsulated using the QVariant constructor. Ultimately, the entire TOML file is completely converted into a QVariantHash object containing a multi-level nested structure, which is returned to the application layer. The fourth read sub-rule instructs that the basic TOML data be mapped to the corresponding QVariantHash object.

[0045] The QVariantHash object, QVariantList object, and Qt time object are encapsulated into a QVariant object, and the QVariant result is marked as the target to read the Qt file.

[0046] S103. Read the target Qt file and return it to the application layer.

[0047] S104. In response to a write action initiated by the application layer, obtain the target modified Qt file.

[0048] The target modified Qt file is used to indicate the Qt configuration file modified by the user corresponding to the application layer.

[0049] As an example, when the application layer needs to save the modified Qt configuration back to a file, it will call the write interface provided by the middleware mentioned above and pass in the QVariantHash or QVariantMap object in the target modified Qt file.

[0050] S105. Using the second preset mapping rule, convert the target modified Qt file into the corresponding target modified TOML file.

[0051] In one possible implementation, the Qt file is modified based on the target to create a corresponding blank root-level TOML table object.

[0052] In one possible implementation, the content data in the target modified Qt file is traversed according to the type attributes of each Qt data of the container and object in the target modified Qt file, as well as the second preset mapping rule, to obtain the corresponding child TOML objects.

[0053] For example, first create an empty root-level TOML table object. Then begin iterating through the data items in the passed-in Qt container. During the iteration, Qt's meta-object system (QMetaType) is used to dynamically identify the specific type of each value.

[0054] In one possible implementation, the corresponding child TOML objects are inserted into a blank root-level TOML table object to obtain the target modified TOML file.

[0055] Furthermore, the traversal of the target root node based on the type attribute of the target root node and the first preset mapping rule is further explained: When the type attribute of Qt data is QVariantHash or QVariantMap, the content of the target modified Qt file is converted to the corresponding child TOML table object through the first write sub-rule of the second preset mapping rule; wherein, the first write sub-rule is used to indicate that the content data of QVariantHash object or QVariantMap object is mapped to the corresponding child TOML table object.

[0056] When the type attribute of Qt data is QVariantList, the content of the target modified Qt file is converted to the corresponding child TOML array object through the second write sub-rule of the second preset mapping rule; wherein, the second write sub-rule is used to indicate that the content data of the QVariantList object is mapped to the corresponding child TOML array object.

[0057] When the type attribute of Qt data is QDate, QTime, or QDateTime, the content of the target modified Qt file is converted to the corresponding child TOML date and time object through the third write sub-rule of the second preset mapping rule; wherein, the third write sub-rule is used to indicate that the content data of QDate, QTime, or QDateTime object is mapped to the corresponding child TOML date and time object.

[0058] For example, in combination Figure 3As shown, the system iterates through the data items in the passed-in Qt container. If Qt's meta-object system recognizes that the current element value, i.e., the key-value pair, is of type QMetaType::QVariantHash or QMetaType::QVariantMap in the nested container, a new child-level TOML table object is created based on the first write sub-rule. The conversion function is then recursively called to fill the child-level table object with the TOML content corresponding to QVariantHash or QVariantMap from the type mapping table. To optimize memory efficiency, this embodiment uses move semantics (std::move) when inserting the child-level table object into the parent-level table object, avoiding unnecessary deep copy operations.

[0059] If Qt's meta-object system recognizes that the value is of type QMetaType::QVariantList in a nested container, it creates a new child TOML array object based on the second write sub-rule. Then, it iterates through each element in the type map corresponding to the QVariantList, converts it to the corresponding TOML node, and inserts it into the child TOML array object.

[0060] If the value is identified as a date / time type such as QMetaType::QDate, QMetaType::QTime, or QMetaType::QDateTime, the specific time component is extracted from the Qt object based on the third write sub-rule, and a date / time node conforming to the TOML specification is constructed. This achieves automatic time format alignment, converting Qt time to TOML time. For example, for a QDate object, the system extracts the return values ​​of its year(), month(), and day() methods to construct the node.

[0061] For other common types, perform direct numerical conversion, such as converting Qt types to C++ types.

[0062] S106. Store the target modified TOML file to the external storage layer.

[0063] In one possible implementation, combining Figure 3 As shown, after completing the transformation and construction of all data, that is, after completing the container traversal, the constructed TOML root table object is serialized into a text format file stream using the file output stream and written to the physical disk, that is, the external storage layer.

[0064] In this embodiment, in response to a read action initiated by the application layer, the target TOML file indicating the TOML configuration file the application layer wants to access is obtained. Then, using a first preset mapping rule to convert data of the TOML standard type into the corresponding Qt meta type, the target TOML file is converted into a corresponding target Qt file, and the target Qt file is returned to the application layer. In response to a write action initiated by the application layer, the target modified Qt file indicating the modified Qt configuration file is obtained. Using a second preset mapping rule to convert data of the Qt meta type into the corresponding TOML standard type, the target modified Qt file is converted into a corresponding target modified TOML file, and the target modified TOML file is stored in the external storage layer. Thus, by combining the first and second preset mapping rules, this application achieves seamless integration between TOML data and the core Qt data structure. Developers do not need to worry about the underlying parsing details and type conversions; they can read and write TOML files as easily as manipulating JSON, significantly improving the development efficiency of the configuration management module in Qt applications and reducing code maintenance costs.

[0065] In some embodiments, this application also provides a TOML to Qt bidirectional data conversion apparatus. This TOML to Qt bidirectional data conversion apparatus may include one or more functional modules for implementing the TOML to Qt bidirectional data conversion method of the above method embodiments.

[0066] For example, Figure 4 This is a schematic diagram illustrating the composition of a TOML to Qt bidirectional data conversion device provided in an embodiment of this application. Figure 4 As shown, the TOML to Qt bidirectional data conversion device includes: a first acquisition module 401, a first processing module 402, a second acquisition module 403, and a second processing module 404.

[0067] The first acquisition module 401 is used to acquire the target TOML file to be read in response to the application layer initiating a read action; wherein the target TOML file is used to indicate the TOML configuration file that the application layer wants to access.

[0068] The first processing module 402 is used to convert a target TOML file into a corresponding target Qt file using a first preset mapping rule; wherein, the first preset mapping rule is used to convert data of the TOML standard type into data of the corresponding Qt meta type.

[0069] The first processing module 402 is also used to return the target read Qt file to the application layer.

[0070] The second acquisition module 403 is used to acquire the target modified Qt file in response to the application layer initiating a write action; wherein the target modified Qt file is used to indicate the Qt configuration file modified by the application layer.

[0071] The second processing module 404 is used to convert the target modified Qt file into the corresponding target modified TOML file through the second preset mapping rule; wherein, the second preset mapping rule is used to convert Qt meta type data into corresponding TOML standard type data.

[0072] The second processing module 404 is also used to store the target modified TOML file to an external storage layer.

[0073] In some embodiments, the first acquisition module 401 is further configured to perform path validity verification on the target read TOML file; wherein, path validity verification is used to verify whether the target read TOML file exists in the external storage layer; In response to the successful path validation for the target to read the TOML file, permission verification is performed on the target to read the TOML file; the permission verification is used to check whether the user corresponding to the application layer has read permission to read the target TOML file. In response to the successful permission verification of the target TOML file, the target TOML file is converted into the corresponding target Qt file according to the first preset mapping rule.

[0074] In some embodiments, the first processing module 402 is specifically used to load the contents of the target read TOML file as the target root node; Based on the type attribute of the target root node and the first preset mapping rule, the target root node is traversed to obtain the corresponding target Qt file.

[0075] In some embodiments, the first processing module 402 is specifically used to, in response to the target root node's type attribute being a TOML table type, convert and insert the content in the target root node into the corresponding QVariantHash object through the first reading sub-rule of the first preset mapping rule; wherein, the first reading sub-rule is used to instruct the mapping of TOML table type content data to the corresponding QVariantHash object; When the type attribute of the target root node is a TOML array type, the content in the target root node is converted and inserted into the corresponding QVariantList object through the second read sub-rule of the first preset mapping rule; wherein, the second read sub-rule is used to indicate that the content data of the TOML array type is mapped to the corresponding QVariantList object; When the type attribute of the target root node is time or date, the content in the target root node is converted to the corresponding Qt time object through the third read sub-rule of the first preset mapping rule; wherein, the third read sub-rule is used to indicate that the content data of the TOML array type is mapped to the corresponding Qt time object; Mark the QVariantHash object, QVariantList object, and Qt time object as targets to read the Qt file.

[0076] In some embodiments, the second processing module 404 is specifically used to create a corresponding blank root-level TOML table object based on the target modified Qt file. Based on the type attributes of each Qt data in the target modified Qt file and the second preset mapping rule, the content data in the target modified Qt file is traversed to obtain the corresponding child TOML objects; Insert the corresponding child TOML objects into the blank root TOML table object to obtain the target modified TOML file.

[0077] In some embodiments, the second processing module 404 is specifically used to, in response to the type attribute of Qt data being QVariantHash or QVariantMap, convert the content of the target modified Qt file to the corresponding child TOML table object through the first write sub-rule of the second preset mapping rule; wherein, the first write sub-rule is used to instruct the content data of the QVariantHash object or QVariantMap object to be mapped to the corresponding child TOML table object; When the type attribute of Qt data is QVariantList, the content of the target modified Qt file is converted to the corresponding child TOML array object through the second write sub-rule of the second preset mapping rule; wherein, the second write sub-rule is used to indicate that the content data of the QVariantList object is mapped to the corresponding child TOML array object; When the type attribute of Qt data is QDate, QTime, or QDateTime, the content of the target modified Qt file is converted to the corresponding child TOML date and time object through the third write sub-rule of the second preset mapping rule; wherein, the third write sub-rule is used to indicate that the content data of QDate, QTime, or QDateTime object is mapped to the corresponding child TOML date and time object.

[0078] Figure 5This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device includes: a processor 502, a communication interface 503, and a bus 504. Optionally, the electronic device may also include a memory 501.

[0079] Processor 502 may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 502 may be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 502 may also be a combination of functions implementing computing capabilities, such as a combination including CPU0 and CPU1, a DSP, and a microprocessor.

[0080] The communication interface 503 includes a receiving unit and a transmitting unit, and is used to connect with other devices via a communication network. This communication network can be Ethernet, a wireless access network, a wireless local area network (WLAN), etc.

[0081] The memory 501 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), disk storage medium or other magnetic storage device, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but is not limited thereto.

[0082] In one possible implementation, the memory 501 can exist independently of the processor 502. The memory 501 can be connected to the processor 502 via a bus 504 and is used to store instructions or program code. When the processor 502 calls the instructions or program code stored in the memory 501, it can implement the TOML and Qt data bidirectional conversion method provided in this embodiment of the invention.

[0083] In another possible implementation, the memory 501 can also be integrated with the processor 502.

[0084] Bus 504 can be an extended industry standard architecture (EISA) bus, etc. Bus 504 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0085] Through the above description of the implementation methods, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the service calling device can be divided into different functional modules to complete all or part of the functions described above.

[0086] This application also provides a computer-readable storage medium. All or part of the processes in the above method embodiments can be executed by computer instructions instructing related hardware. The program can be stored in the aforementioned computer-readable storage medium, and when executed, it can include the processes of the above method embodiments. The computer-readable storage medium can be any of the foregoing embodiments or memory. The aforementioned computer-readable storage medium can also be an external storage device of the aforementioned service invocation device, such as a plug-in hard drive, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the aforementioned service invocation device. Further, the aforementioned computer-readable storage medium can include both internal storage units of the aforementioned service invocation device and external storage devices. The aforementioned computer-readable storage medium is used to store the aforementioned computer program and other programs and data required by the aforementioned service invocation device. The aforementioned computer-readable storage medium can also be used to temporarily store data that has been output or will be output.

[0087] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for bidirectional data conversion between TOML and Qt, characterized in that, The method includes: In response to an application layer initiating a read action, the target TOML file to be read is obtained; wherein, the target TOML file is used to indicate the TOML configuration file that the application layer wants to access; The target TOML file is converted into a corresponding target Qt file using a first preset mapping rule; wherein, the first preset mapping rule is used to convert TOML standard type data into corresponding Qt meta type data; The target reads the Qt file and returns it to the application layer; In response to the application layer initiating a write action, the target modified Qt file is obtained; wherein, the target modified Qt file is used to indicate the Qt configuration file modified by the application layer; The target modified Qt file is converted into a corresponding target modified TOML file using a second preset mapping rule; wherein, the second preset mapping rule is used to convert Qt meta-type data into corresponding TOML standard type data; The target modified TOML file is stored in an external storage layer.

2. The method for bidirectional conversion of TOML and Qt data according to claim 1, characterized in that, Before converting the target TOML file into the corresponding target Qt file using the first preset mapping rule, the method further includes: The target TOML file is subjected to path validity verification; wherein, the path validity verification is used to check whether the target TOML file exists in the external storage layer; In response to the successful path validity verification of the target TOML file, permission verification is performed on the target TOML file; wherein, the permission verification is used to check whether the user corresponding to the application layer has read permission to read the target TOML file; In response to the successful permission verification of the target TOML file, the target TOML file is converted into a corresponding target Qt file according to the first preset mapping rule.

3. The method for bidirectional conversion of TOML and Qt data according to claim 1, characterized in that, The step of converting the target TOML file into a corresponding target Qt file using a first preset mapping rule includes: The target reads the contents of the TOML file and loads them as the target root node; Based on the type attribute of the target root node and the first preset mapping rule, the target root node is traversed to obtain the corresponding target Qt file.

4. The method for bidirectional conversion of TOML and Qt data according to claim 3, characterized in that, The step of traversing the target root node based on the type attribute of the target root node and the first preset mapping rule includes: When the type attribute of the target root node is a TOML table type, the content in the target root node is converted and inserted into the corresponding QVariantHash object through the first reading sub-rule of the first preset mapping rule; wherein, the first reading sub-rule is used to indicate that the content data of the TOML table type is mapped to the corresponding QVariantHash object; When the type attribute of the target root node is a TOML array type, the content in the target root node is converted and inserted into the corresponding QVariantList object through the second reading sub-rule of the first preset mapping rule; wherein, the second reading sub-rule is used to indicate that the content data of the TOML array type is mapped to the corresponding QVariantList object; When the type attribute of the target root node is time or date, the content in the target root node is converted to the corresponding Qt time object through the third reading sub-rule of the first preset mapping rule; wherein, the third reading sub-rule is used to indicate that the content data of the TOML array type is mapped to the corresponding Qt time object; The QVariantHash object, QVariantList object, and Qt time object are marked as the target to read the Qt file.

5. The method for bidirectional conversion of TOML and Qt data according to claim 1, characterized in that, The step of converting the target modified Qt file into a corresponding target modified TOML file using a second preset mapping rule includes: Modify the Qt file based on the stated objective and create a corresponding blank root-level TOML table object; Based on the type attributes of each Qt data in the container of the target modified Qt file and the second preset mapping rule, the content data in the target modified Qt file is traversed to obtain the corresponding child TOML objects; Each of the corresponding child TOML objects is inserted into the blank root TOML table object to obtain the target modified TOML file.

6. The method for bidirectional conversion of TOML and Qt data according to claim 5, characterized in that, The step of iterating through the content data in the target modified Qt file according to the type attributes of each Qt data in the container and the second preset mapping rule to obtain the corresponding child TOML objects includes: When the type attribute of the Qt data is QVariantHash or QVariantMap, the content of the target modified Qt file is converted to the corresponding child TOML table object through the first write sub-rule of the second preset mapping rule; wherein, the first write sub-rule is used to indicate that the content data of the QVariantHash object or QVariantMap object is mapped to the corresponding child TOML table object; When the type attribute of the Qt data is QVariantList, the content of the target modified Qt file is converted to the corresponding child TOML array object through the second write sub-rule of the second preset mapping rule; wherein, the second write sub-rule is used to indicate that the content data of the QVariantList object is mapped to the corresponding child TOML array object; When the type attribute of the Qt data is QDate, QTime, or QDateTime, the content of the target modified Qt file is converted to the corresponding child TOML date and time object through the third write sub-rule of the second preset mapping rule; wherein, the third write sub-rule is used to instruct the content data of the QDate, QTime, or QDateTime object to be mapped to the corresponding child TOML date and time object.

7. A bidirectional data conversion device between TOML and Qt, characterized in that, include: The first acquisition module is used to acquire the target TOML file to be read in response to the application layer initiating a read action; wherein the target TOML file is used to indicate the TOML configuration file that the application layer wants to access; The first processing module is used to convert the target TOML file into a corresponding target Qt file using a first preset mapping rule; wherein, the first preset mapping rule is used to convert data of the TOML standard type into data of the corresponding Qt meta type. The first processing module is further configured to return the target read Qt file to the application layer; The second acquisition module is used to acquire the target modified Qt file in response to the application layer initiating a write action; wherein the target modified Qt file is used to indicate the Qt configuration file modified by the application layer; The second processing module is used to convert the target modified Qt file into a corresponding target modified TOML file using a second preset mapping rule; wherein, the second preset mapping rule is used to convert Qt meta-type data into corresponding TOML standard type data; The second processing module is also used to store the target modified TOML file to an external storage layer.

8. An electronic device, characterized in that, It includes a processor and a memory, the processor being coupled to the memory; the memory is used to store computer instructions, which are loaded and executed by the processor to enable the computer device to perform the method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes computer-executable instructions that, when executed on a computer, cause the computer to perform the method according to any one of claims 1 to 6.

10. A computer program product, characterized in that, The computer program product includes a computer program that, when run on an electronic device, causes the electronic device to perform the method as described in any one of claims 1 to 6.