Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Dynamic XML documents instead of `.ui` files in Qt
QtWS25 Last Chance

Dynamic XML documents instead of `.ui` files in Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
xmldesktopxsltquiloaderui file
11 Posts 3 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    brainchild
    wrote on last edited by
    #1

    The class QUiLoader represents elements of a graphical user interface, of Qt components, described by an XML document. A common design pattern would be a build process integrating a static document into the application as a resource. Another would be code generation at build time.

    Consider the possibility of describing part of a user interface through an XML document that would be dynamically constructed, such as through an XSLT transformation provided by Xalan-C++. In an XML-driven application, such a design opens possibilities not readily available from more widespread patterns.

    Yet, it may appear from the documentation that the only interface for passing XML data to be utilized by QUiLoader is through the invocation of the method load() invoked by passing an instance of QIODevice. Such a call supports streaming data of serialized form. Naturally, intermediary serialization or parsing operations are unnecessary, at least in principle, and unpreferred.

    Following are two questions:

    1. Is such a strategy viable, in terms of authoring a Qt application for which some of the presentation layout is resolved dynamically in such a manner?
    2. Is a superior approach available, for displaying presentation represented by a dynamically-generated XML document, compared to passing a string representation of it, through Qt?
    1 Reply Last reply
    0
    • kkoehneK Offline
      kkoehneK Offline
      kkoehne
      Moderators
      wrote on last edited by
      #2

      QUILoader indeed allows to load .ui files at runtime, via QUILoader::load(). How you end up with the XML that constitutes the XML file is up to you. So yeah, I don't see why your setup shouldn't work. Keep in mind though that, compared to the more traditional uic approach, you're moving work from compile time to runtime, which makes error checking harder, but also creates some delay at runtime.

      One alternative is using Qt Quick, and it's language QML. This is not XML though, but you could of course generate a QML file out of an XML file by transformation.

      Director R&D, The Qt Company

      1 Reply Last reply
      0
      • kkoehneK Offline
        kkoehneK Offline
        kkoehne
        Moderators
        wrote on last edited by
        #3

        Yet, it may appear from the documentation that the only interface for passing XML data to be utilized by QUiLoader is through the invocation of the method load() invoked by passing an instance of QIODevice. Such a call supports streaming data of serialized form. Naturally, intermediary serialization or parsing operations are unnecessary, at least in principle, and unpreferred.

        Well, XML by definition is serialized. If you want to start with something like a in-memory DOM, you could implement your own UILoader functionality quite easily, but there's no ready-made API for that.

        If your concern is only that you don't want to do disk-io, please be aware that a QIODevice can also be a purely in-memory data storage, like QBuffer.

        Director R&D, The Qt Company

        B 1 Reply Last reply
        0
        • kkoehneK kkoehne

          Yet, it may appear from the documentation that the only interface for passing XML data to be utilized by QUiLoader is through the invocation of the method load() invoked by passing an instance of QIODevice. Such a call supports streaming data of serialized form. Naturally, intermediary serialization or parsing operations are unnecessary, at least in principle, and unpreferred.

          Well, XML by definition is serialized. If you want to start with something like a in-memory DOM, you could implement your own UILoader functionality quite easily, but there's no ready-made API for that.

          If your concern is only that you don't want to do disk-io, please be aware that a QIODevice can also be a purely in-memory data storage, like QBuffer.

          B Offline
          B Offline
          brainchild
          wrote on last edited by brainchild
          #4

          @kkoehne said in Dynamic XML documents instead of `.ui` files in Qt:

          Well, XML by definition is serialized. If you want to start with something like a in-memory DOM, you could implement your own UILoader functionality quite easily, but there's no ready-made API for that.
          If your concern is only that you don't want to do disk-io, please be aware that a QIODevice can also be a purely in-memory data storage, like QBuffer.

          The concern is not about avoiding I/O, but about being forced to use serialized form as the only available means for passing a document in memory.

          Would you please clarify the sense in which implementing the functionality of QUiLoader is "quite easy", as doing so would seem to me to involve completely creating a processor for the semantics of the UI language, to build a widget representation based on the content of the UI document, as I understand to be the function of QUiLoader.

          Christian EhrlicherC kkoehneK 2 Replies Last reply
          0
          • B brainchild

            @kkoehne said in Dynamic XML documents instead of `.ui` files in Qt:

            Well, XML by definition is serialized. If you want to start with something like a in-memory DOM, you could implement your own UILoader functionality quite easily, but there's no ready-made API for that.
            If your concern is only that you don't want to do disk-io, please be aware that a QIODevice can also be a purely in-memory data storage, like QBuffer.

            The concern is not about avoiding I/O, but about being forced to use serialized form as the only available means for passing a document in memory.

            Would you please clarify the sense in which implementing the functionality of QUiLoader is "quite easy", as doing so would seem to me to involve completely creating a processor for the semantics of the UI language, to build a widget representation based on the content of the UI document, as I understand to be the function of QUiLoader.

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @brainchild said in Dynamic XML documents instead of `.ui` files in Qt:

            The concern is not about avoiding I/O, but about being forced to use serialized form as the only available means for passing a document in memory.

            What does this mean? You somehow must pass the data to the uiloader class. And this is a QIODevice which can be a QFile or QBuffer or something else.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            B 1 Reply Last reply
            0
            • B brainchild

              @kkoehne said in Dynamic XML documents instead of `.ui` files in Qt:

              Well, XML by definition is serialized. If you want to start with something like a in-memory DOM, you could implement your own UILoader functionality quite easily, but there's no ready-made API for that.
              If your concern is only that you don't want to do disk-io, please be aware that a QIODevice can also be a purely in-memory data storage, like QBuffer.

              The concern is not about avoiding I/O, but about being forced to use serialized form as the only available means for passing a document in memory.

              Would you please clarify the sense in which implementing the functionality of QUiLoader is "quite easy", as doing so would seem to me to involve completely creating a processor for the semantics of the UI language, to build a widget representation based on the content of the UI document, as I understand to be the function of QUiLoader.

              kkoehneK Offline
              kkoehneK Offline
              kkoehne
              Moderators
              wrote on last edited by
              #6

              @brainchild said in Dynamic XML documents instead of `.ui` files in Qt:

              Would you please clarify the sense in which implementing the functionality of QUiLoader is "quite easy", as doing so would seem to me to involve completely creating a processor for the semantics of the UI language, to build a widget representation based on the content of the UI document, as I understand to be the function of QUiLoader.

              "quite easy" was probably an exaggeration. What I meant is that such a mapping is conceptually not complicated - The C++ API of Qt Widgets allows you to do stuff imperatively, after all. But depending on the scope (which widgets, properties, ... you want to support), it might still be a lot of work, sure.

              Director R&D, The Qt Company

              B 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @brainchild said in Dynamic XML documents instead of `.ui` files in Qt:

                The concern is not about avoiding I/O, but about being forced to use serialized form as the only available means for passing a document in memory.

                What does this mean? You somehow must pass the data to the uiloader class. And this is a QIODevice which can be a QFile or QBuffer or something else.

                B Offline
                B Offline
                brainchild
                wrote on last edited by
                #7

                @Christian-Ehrlicher said in Dynamic XML documents instead of `.ui` files in Qt:

                @brainchild said in Dynamic XML documents instead of `.ui` files in Qt:

                The concern is not about avoiding I/O, but about being forced to use serialized form as the only available means for passing a document in memory.

                What does this mean? You somehow must pass the data to the uiloader class. And this is a QIODevice which can be a QFile or QBuffer or something else.

                Usually serialized form is for I/O, not internal processing. It may work in principle to pass serialized strings across an application, but is not preferred. Most processing of XML documents at some point requires a random-access negotiation of the tree, hence the emergence of DOM.

                Christian EhrlicherC 1 Reply Last reply
                0
                • kkoehneK kkoehne

                  @brainchild said in Dynamic XML documents instead of `.ui` files in Qt:

                  Would you please clarify the sense in which implementing the functionality of QUiLoader is "quite easy", as doing so would seem to me to involve completely creating a processor for the semantics of the UI language, to build a widget representation based on the content of the UI document, as I understand to be the function of QUiLoader.

                  "quite easy" was probably an exaggeration. What I meant is that such a mapping is conceptually not complicated - The C++ API of Qt Widgets allows you to do stuff imperatively, after all. But depending on the scope (which widgets, properties, ... you want to support), it might still be a lot of work, sure.

                  B Offline
                  B Offline
                  brainchild
                  wrote on last edited by
                  #8

                  @kkoehne said in Dynamic XML documents instead of `.ui` files in Qt:

                  "quite easy" was probably an exaggeration. What I meant is that such a mapping is conceptually not complicated - The C++ API of Qt Widgets allows you to do stuff imperatively, after all. But depending on the scope (which widgets, properties, ... you want to support), it might still be a lot of work, sure.

                  Exact congruity in behavior is hard requirement.

                  1 Reply Last reply
                  0
                  • B brainchild

                    @Christian-Ehrlicher said in Dynamic XML documents instead of `.ui` files in Qt:

                    @brainchild said in Dynamic XML documents instead of `.ui` files in Qt:

                    The concern is not about avoiding I/O, but about being forced to use serialized form as the only available means for passing a document in memory.

                    What does this mean? You somehow must pass the data to the uiloader class. And this is a QIODevice which can be a QFile or QBuffer or something else.

                    Usually serialized form is for I/O, not internal processing. It may work in principle to pass serialized strings across an application, but is not preferred. Most processing of XML documents at some point requires a random-access negotiation of the tree, hence the emergence of DOM.

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @brainchild The uiloader is just a way to load xml files which in 99,9% are processed by uic and compiled directly instead. So adding this complexity to pass a DOM instead a simple QIODevice for the max. 0,1% use case is fine in my pov.
                    Esp.since there is no need for a DOM and QtCore don't have a DOM class at all - QXmlStreamReader is perfectly fine for this simple task.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    B 2 Replies Last reply
                    0
                    • Christian EhrlicherC Christian Ehrlicher

                      @brainchild The uiloader is just a way to load xml files which in 99,9% are processed by uic and compiled directly instead. So adding this complexity to pass a DOM instead a simple QIODevice for the max. 0,1% use case is fine in my pov.
                      Esp.since there is no need for a DOM and QtCore don't have a DOM class at all - QXmlStreamReader is perfectly fine for this simple task.

                      B Offline
                      B Offline
                      brainchild
                      wrote on last edited by brainchild
                      #10

                      @Christian-Ehrlicher said in Dynamic XML documents instead of `.ui` files in Qt:

                      @brainchild The uiloader is just a way to load xml files which in 99,9% are processed by uic and compiled directly instead. So adding this complexity to pass a DOM instead a simple QIODevice for the max. 0,1% use case is fine in my pov.
                      Esp.since there is no need for a DOM and QtCore don't have a DOM class at all - QXmlStreamReader is perfectly fine for this simple task.

                      It would be an improvement, though, if the builder were not tied to I/O or strings, even if mostly it would be used in such a way. The class QXMLStreamReader could be refactored to descend from an abstract parent, which could be used as a source for the builder, as a parameter to a new method, with the builder then being refactoring such that the existing methods would utilize the new one.

                      At any rate, I understand the responses given, that any application based on the current platform must use strings if not I/O.

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @brainchild The uiloader is just a way to load xml files which in 99,9% are processed by uic and compiled directly instead. So adding this complexity to pass a DOM instead a simple QIODevice for the max. 0,1% use case is fine in my pov.
                        Esp.since there is no need for a DOM and QtCore don't have a DOM class at all - QXmlStreamReader is perfectly fine for this simple task.

                        B Offline
                        B Offline
                        brainchild
                        wrote on last edited by
                        #11

                        @Christian-Ehrlicher said in Dynamic XML documents instead of `.ui` files in Qt:

                        @brainchild The uiloader is just a way to load xml files which in 99,9% are processed by uic and compiled directly instead. So adding this complexity to pass a DOM instead a simple QIODevice for the max. 0,1% use case is fine in my pov.
                        Esp.since there is no need for a DOM and QtCore don't have a DOM class at all - QXmlStreamReader is perfectly fine for this simple task.

                        The XML module has a DOM representation. Why would it not be sensible for a version to be provided of load() that processes a DOM representation from this module?

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved