转自:
http://akreuzkamp.de/2013/07/10/webapps-written-in-qml-not-far-from-reality-anymore/ WebApps written in QML: Not far from Reality anymore Haveyou ever tried to vertically center an element using CSS or wanted anelement to just use the whole remaining space or similar things? Did youever struggle with complex interfaces when writing a modern website?Did you ever use QML for a desktop-app and were in wonder how amazinglyit just works? Then there probably was also the point where youthought ”why can’t I just use QML for my webapp?”. So have I.
And in fact it is nearer to reality than you would think:
Say hello to QmlWeb.
QmlWeb is a JavaScript library that is able to parse QML-code andcreate a website out of it using normal HTML/DOM elements and absolutepositions within CSS, translating the QML properties into CSSproperties. Currently it’s also able to paint into a canvas but ascanvas is far less powerful, that’s probably going to be dropped. Sousing the DOM-backend there is no need for HTML5. The webbrowser needsto support ECMAScript5 for now, though.
QmlWeb is a small project by Lauri Paimen that he’s already developingfor a few years now. In the last months, I entered into the developmentrefactoring parts of the library, so by now Lauri yielded themaintainance to me. The biggest part of the credits, though, are due tohim.
As of today, I’m proud to announce that
QmlWeb will be from now on a KDE-Project.
(A small prototype of a website for QmlWeb – of course written using QML

)
QmlWeb of course doesn’t yet support everything Qt’s implementationof QML does, but it already supports a quite usable subset of it. Itsupports nearly all of the most basic QML syntax. The element types itsupports, are
- Item
- Rectangle
- Text
- Image
- BorderImage
- MouseArea
- Repeater
- ListModel
- NumberAnimation
- SequentialAnimation
Moreover it has support for HTML input elements (Button, TextInput, TextArea are currently supported, more to come).
Positioning using anchors works like a charm, Componentswork too, so does the signal-slot system. Basic animations work nicely(Animations in QML are most probably far more powerful, but what worksin QmlWeb is already quite nice

). Keyboard-control is missing as well as States. Layouts (Row, Column, etc.) are currently under development.
Of course there are many more little features missing, but thelibrary is already quite usable. In fact I’m already using it for onewebapp, I’m currently writing. There are some places where I’m stillusing direct html/css, but that’s another nice feature of QmlWeb. Youcan easily integrate it with normal html/css: QmlWeb exposes theelement-id to css-classes, so you can easily include a stylesheet inyour surrounding html-file and set all css-properties, you can’t control(yet) with QML, to your QML-element.
That’s soooo awesome! How can I use it? Just grab the latest code from git://anongit.kde.org/qmlweb, put theqmlweb folder in the same directory like your webpage and put thefollowing code into your index.html:
- <!DOCTYPE html>
- <html>
- <head>
- <title>QmlWeb Demo</title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <script type="text/javascript" src="../qmlweb/src/parser.js"></script>
- <script type="text/javascript" src="../qmlweb/src/process.js"></script>
- <script type="text/javascript" src="../qmlweb/src/import.js"></script>
- <script type="text/javascript" src="../qmlweb/src/qtcore.js"></script>
- </head>
- <body style="margin: 0;">
- <script type="text/javascript">
- var qmlEngine = new QMLEngine(document.body, {});
- qmlEngine.loadFile("main.qml");
- qmlEngine.start();
- </script>
- </body>
- </html>
Then add a file main.qml containing your QML-coded website.
But it can’t do XYZ!! Well, QmlWeb is not finished, yet. And
I’m looking for people willing to help. 
Just grab the code, fix it and get in touch with me: <my nick>@web.de (my nick btw. is akreuzkamp

)
A reviewboard-section, a irc-channel and a mailinglist for qmlweb will come soon.
Btw.:

Edit: I added information about how it renders QML to websites(QmlWeb is using normal HTML/DOM elements and absolute positions withinCSS, translating the QML properties into CSS properties to paintelements).