Results 1 to 15 of 15

Thread: XML to QML converter

  1. #1
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default XML to QML converter

    Hello all,

    I am working on a project which I use QML to draw my GUI. But somehow I need to generate QML files from XML based solution like this;

    Qt Code:
    1. <general>
    2. <text name="src_text1" value="this is text 1" />
    3. <text name="src_text2" value="this is text 2" />
    4. <image name="src_image1" location="/opt/cutekit/data/images/qt.png">
    5. <!-- many more slots to come! -->
    6. </general>
    To copy to clipboard, switch view to plain text mode 

    to;

    Qt Code:
    1. Rectangle {
    2. width: 1920
    3. height: 1080
    4. color: "#00000000"
    5.  
    6. Text {
    7. id: text1
    8. x: 252
    9. y: 574
    10. width: 80
    11. height: 20
    12. text: src_text1
    13. font.pixelSize: 12
    14. opacity: 0
    15. }
    16.  
    17. Text {
    18. id: text2
    19. x: 492
    20. y: 574
    21. width: 80
    22. height: 20
    23. text: src_text2
    24. font.pixelSize: 12
    25. opacity: 0
    26. }
    27.  
    28. Image {
    29. id: image1
    30. x: 772
    31. y: 297
    32. width: 100
    33. height: 100
    34. source: src_image1
    35. opacity: 0
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 


    So my question is, do I have to do this manually on runtime(parsing xml, creating qml file), or is there any tool to help me on this one?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: XML to QML converter

    What is the use of expressing QML in XML?
    Why not use QML directly?
    What are you trying to achieve?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: XML to QML converter

    Hello,

    I know that sounds stupid and actually that was what I proposed at first , but development head
    wants to use generated XML's for more that one project... so they do not want to deal with QML creation and stuff.
    so I need to write some tool for that matter I guess.


    Added after 15 minutes:


    Anyway,

    if any other person needs something like this, check that project on gitorious
    https://gitorious.org/xml2qml
    Last edited by mburakalkan; 21st April 2011 at 13:19.

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML to QML converter

    Have you tried with QtXmlPatterns module?

    See here for more details.
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: XML to QML converter

    I would rather ask why you want to use qml at all. Since you don't want to be bound to qml, you won't be able to use any of qml's declarative features which implies your xml file will only contain a static structure of elements. Generating a ui file (e.g. using xslt) seems more appropriate in this situation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: XML to QML converter

    @wysota actually all the application based on graphics/declarative view, application does not contain QWidget based standart Qt widgets, but graphicsitem based stuff (images/text etc.) so in this case I actually want to use to decouple what do draw and when to draw, animation and state support etc.. I don't want to use graphicsview classes to do the all drawing, so basically QML will be my ui file.. see project details at https://gitorious.org/cutekit so in this case that makes sense right?

    @mcosta thanks for suggestion!

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: XML to QML converter

    Quote Originally Posted by mburakalkan View Post
    @wysota actually all the application based on graphics/declarative view, application does not contain QWidget based standart Qt widgets, but graphicsitem based stuff (images/text etc.) so in this case I actually want to use to decouple what do draw and when to draw, animation and state support etc.. I don't want to use graphicsview classes to do the all drawing, so basically QML will be my ui file.. see project details at https://gitorious.org/cutekit so in this case that makes sense right?
    No, not really. In this situation I would use the xml file directly and build Graphics View objects from it in code. I don't see any advantage from using qml here.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    mburakalkan (22nd April 2011)

  9. #8
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML to QML converter

    I agree with wysota.

    I think QML is usefull for non-programmers ui designers.
    I prefer use Graphics View Framework.
    A camel can go 14 days without drink,
    I can't!!!

  10. The following user says thank you to mcosta for this useful post:

    mburakalkan (22nd April 2011)

  11. #9
    Join Date
    Sep 2010
    Posts
    10
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: XML to QML converter

    I guess I need to review application workflow here, maybe using QML is not that advantageous here as you say..

    BTW I heard actually using DeclarativeView + QML is more performance sane vs using plain GraphicsView even though
    former is based on latter, since they do a lot of optimization drawing with QML(lazy loading, and other stuff etc..) what do you guys
    think about that?

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: XML to QML converter

    Quote Originally Posted by mburakalkan View Post
    BTW I heard actually using DeclarativeView + QML is more performance sane vs using plain GraphicsView even though
    former is based on latter, since they do a lot of optimization drawing with QML(lazy loading, and other stuff etc..) what do you guys
    think about that?
    You can do the exact same optimizations in your code. Besides there is no point in worrying about optimizations if you're not suffering from efficiency problems.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #11
    Join Date
    Apr 2012
    Location
    Russia, Novorossiysk
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML to QML converter

    Good time of day.
    I have (almost) the same problem, but let me describe it in details.
    What has to be done: user double-clicks on config file (list of XML files) and a nice GUI magically appears where he can change values of attributes.
    The way I see it can be one: transform XML into QML via XSLT and show that, +inform the user if there is unrecognized fields detected (i.e. wrong config structure).
    Why bother with transformation? Boss doesn't want the analytical part to be hardcoded with C++, a config template should be "easily" editable on-the-go. XSLT template fits here nicely since it can allow me to check and "easily" modify the config structure. The problem is that meh completely unfamiliar with XSTL and QML -.- soooo
    The question: can it all be done in a more elegant way? (I feel like I'm looking for some magical tool that will do all the work instantly, duh )

    (p.s. As alternative to QML I can see only QUiLoader, but QML is imo more pretty)
    Last edited by BreezeUA; 10th September 2012 at 14:33.

  14. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: XML to QML converter

    You want to make a config editor or does the xml file contain the contents of what you want to display? Either way I don't think QML is a good approach here (unless the XML contains a description of some fancy graphical scene). Parse the XML and generate your UI from it using C++ and widgets.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #13
    Join Date
    Apr 2012
    Location
    Russia, Novorossiysk
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML to QML converter

    I need a config editor (actually it's just a part of an utility that allows to control the modules of an application). Let's suppose I made a DOM parser to read the data directly and placed it all on widgets - plain and easy. But when I need to change the config structure, or the way it is shown on a form I have to modify and recompile my app, right? As I mentioned above it's (unfortunately) not an option, so I need some middle layer of something that will allow me to describe that config logical and visual structure (QT UI file / QML file / ?..) and then transform input config into that something, process it and get some QObject I can work with in result. So when the user (another programmer really) wants to change the visuals/logic he just changes the "script" text, nothing more.

  16. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: XML to QML converter

    Quote Originally Posted by BreezeUA View Post
    But when I need to change the config structure, or the way it is shown on a form I have to modify and recompile my app, right?
    Possibly yes.

    As I mentioned above it's (unfortunately) not an option, so I need some middle layer of something that will allow me to describe that config logical and visual structure (QT UI file / QML file / ?..) and then transform input config into that something, process it and get some QObject I can work with in result.
    It's like squaring the circle... What if you need to handle something you have not forseen earlier? Trying to be too smart often backfires. Using XSLT if you don't know it has this significant drawback that you waste a lot of time when trying to do anything complex with it. Besides, a good design is one that does not need changing later Spend twice the time you intended to design your xml structure and it will be less probably that you'll need to change it later. By the way, a DOM parser is probably not the best idea unless you make it very generic. QXmlStreamReader would be much more flexible as it practically requires you to write a stateless recursive parser without assuming a pre-defined hierarchy of elements.

    So when the user (another programmer really) wants to change the visuals/logic he just changes the "script" text, nothing more.
    So implement it using a scripting language, e.g. JavaScript (handled by QtScript) or Python (e.g. using PySide).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. The following user says thank you to wysota for this useful post:

    BreezeUA (11th September 2012)

  18. #15
    Join Date
    Apr 2012
    Location
    Russia, Novorossiysk
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: XML to QML converter

    Thanks for ideas! Will dig in that way now

Similar Threads

  1. PDF to Image Converter
    By RajabNatshah in forum Qt Programming
    Replies: 14
    Last Post: 12th January 2024, 00:32
  2. Unit Converter Widget
    By baray98 in forum Qt Programming
    Replies: 13
    Last Post: 17th December 2016, 16:06
  3. Please help. Converter Dec to bin and Hex
    By Novice in forum Newbie
    Replies: 4
    Last Post: 29th March 2011, 10:41
  4. QTest to NUnit, MBUnit or MSTest format xml converter
    By ralphing in forum Qt Programming
    Replies: 1
    Last Post: 7th September 2010, 09:16
  5. Image Converter
    By deekayt in forum General Discussion
    Replies: 1
    Last Post: 30th October 2006, 21:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.