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. How to convert QML to QWidgets .ui XML code?
Forum Updated to NodeBB v4.3 + New Features

How to convert QML to QWidgets .ui XML code?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 3.3k Views 2 Watching
  • 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.
  • E Offline
    E Offline
    Eager
    wrote on 24 Mar 2019, 07:20 last edited by
    #1

    As I am the fan of QML so I want to make a QtCreator plugin so that I may be able to write QWidgets ui in QML like code. QML is readable and takes less real-state.
    My question is how can I convert the following QML like code to the following .ui XML code.
    My proposed QML like code:

    QWidget {
        name: "centralWidget"
        QPushButton {
            name: "pushButton"
            geometry: {
                x: 10
                y: 20
                width: 150
                height: 50
            }
            text: "Hello World!"
        }
    }
    

    .ui XML code:

      <widget class="QWidget" name="centralWidget">
       <widget class="QPushButton" name="pushButton">
        <property name="geometry">
         <rect>
          <x>10</x>
          <y>20</y>
          <width>150</width>
          <height>50</height>
         </rect>
        </property>
        <property name="text">
         <string>Hello World!</string>
        </property>
       </widget>
      </widget>
     </widget>
    

    I would be thankful if someone point me to the right direction or provide me a sample code/library please!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 24 Mar 2019, 09:44 last edited by mrjj
      #2

      Hi
      The QML format is very close to JSON syntax.
      So if you use a relaxed parser like
      https://hjson.org/
      that accepts values with no "" then it should be able to parse most of it.
      or have a look at
      https://github.com/jesperhh/qmlfmt
      to see if it can parse enough. ( and/or use it for the plugin to format the QML)
      If you need full blown parsing, then you could look at
      https://code.woboq.org/qt5/qtdeclarative/src/qml/parser/

      For saving to UI format, you might have a look at
      https://doc.qt.io/qt-5/qabstractformbuilder.html#save
      https://doc.qt.io/qt-5/qformbuilder.html

      However, thats for saving QWidgets runtime so might not be possible with QML objects.

      So you might end up using a XML library.
      https://doc.qt.io/qt-5/qtxml-index.html
      https://pugixml.org/

      to construct the UI files your self from the QML tree.

      1 Reply Last reply
      4
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 24 Mar 2019, 21:29 last edited by
        #3

        Hi,

        You might also want to check KDAB's DeclarativeWidgets project.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • E Offline
          E Offline
          Eager
          wrote on 28 Mar 2019, 08:21 last edited by
          #4

          Went through proper lexical analysis and parsing approach.

          1 Reply Last reply
          1
          • S Offline
            S Offline
            sammtan
            wrote on 9 Nov 2023, 20:38 last edited by
            #5
            This post is deleted!
            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