alex_lipAug. 16, 2018, 4:48 a.m.
Serving UI via HTTP
Продолжаю разбирать примеры - вот пример
===================================================
Serving UI via HTTP
To load a simple user interface via HTTP we need to have a web-server, which serves the UI documents. We start
of with our own simple web-server using a python one-liner. But first we need to have our demo user interface.
For this we create a small main.qml file in our project folder and create a red rectangle inside.
// main.qml
import QtQuick 2.5
Rectangle {
width: 320
height: 320
color: '#ff0000'
}
To serve this file we launch a small python script:
$ cd <PROJECT>
# python -m SimpleHTTPServer 8080
Now our file should be reachable via http://localhost:8080/main.qml. You can test it with:
$ curl http://localhost:8080/main.qml
Or just point your browser to the location. Your browser does not understand QML and will not be able to render
the document through. We need to create now such a browser for QML documents. To render the document we
need to point our qmlscene to the location. Unfortunately the qmlscene is limited to local files only. We
could overcome this limitation by writing our own qmlscene replacement or simple dynamically load it using
QML. We choose the dynamic loading as it works just fine. For this we use a loader element to retrieve for us the
remote document.
// remote.qml
import QtQuick 2.5
Loader {
id: root
source: 'http://localhost:8080/main2.qml'
onLoaded: {
root.width = item.width
root.height = item.height
}
}
Now we can ask the qmlscene to load the local remote.qml loader document. There is one glitch still. The
loader will resize to the size of the loaded item. And our qmlscene needs also to adapt to that size. This can be
accomplished using the --resize-to-root option to the qmlscene:
$ qmlscene --resize-to-root remote.qml
Resize to root tells the qml scene to resize its window to the size of the root element. The remote is now loading
the main.qml from our local server and resizes itself to the loaded user interface. Sweet and simple.
To load a simple user interface via HTTP we need to have a web-server, which serves the UI documents. We start
of with our own simple web-server using a python one-liner. But first we need to have our demo user interface.
For this we create a small main.qml file in our project folder and create a red rectangle inside.
// main.qml
import QtQuick 2.5
Rectangle {
width: 320
height: 320
color: '#ff0000'
}
To serve this file we launch a small python script:
$ cd <PROJECT>
# python -m SimpleHTTPServer 8080
Now our file should be reachable via http://localhost:8080/main.qml. You can test it with:
$ curl http://localhost:8080/main.qml
Or just point your browser to the location. Your browser does not understand QML and will not be able to render
the document through. We need to create now such a browser for QML documents. To render the document we
need to point our qmlscene to the location. Unfortunately the qmlscene is limited to local files only. We
could overcome this limitation by writing our own qmlscene replacement or simple dynamically load it using
QML. We choose the dynamic loading as it works just fine. For this we use a loader element to retrieve for us the
remote document.
// remote.qml
import QtQuick 2.5
Loader {
id: root
source: 'http://localhost:8080/main2.qml'
onLoaded: {
root.width = item.width
root.height = item.height
}
}
Now we can ask the qmlscene to load the local remote.qml loader document. There is one glitch still. The
loader will resize to the size of the loaded item. And our qmlscene needs also to adapt to that size. This can be
accomplished using the --resize-to-root option to the qmlscene:
$ qmlscene --resize-to-root remote.qml
Resize to root tells the qml scene to resize its window to the size of the root element. The remote is now loading
the main.qml from our local server and resizes itself to the loaded user interface. Sweet and simple.
====================================================================================
Питон у меня установлен - но как запустить локальный SimpleHTTPServer - я не понимаю -
когда я пишу в командной строке
C:\qt_buy> python -m SimpleHTTPServer 8080
- ругается -
C:\Python35\python.exe: No module named SimpleHTTPServer
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
AD
- Akiv Doros
- Nov. 11, 2024, 2:58 p.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:50points,
- Rating points-4
m
- molni99
- Oct. 26, 2024, 1:37 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:80points,
- Rating points4
m
- molni99
- Oct. 26, 2024, 1:29 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:20points,
- Rating points-10
Last comments
ИМ
Django - Tutorial 017. Customize the login page to Django Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
Игорь МаксимовNov. 22, 2024, 11:51 a.m.
Evgenii LegotckoiOct. 31, 2024, 2:37 p.m.
Fb3 file reader on Qt Creator Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
ИМ
Django - Lesson 064. How to write a Python Markdown extension Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
Игорь МаксимовOct. 5, 2024, 7:51 a.m.
QML - Lesson 016. SQLite database and the working with it in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
Now discuss on the forum
Evgenii LegotckoiJune 24, 2024, 3:11 p.m.
t
google domain [url=https://google.com/]domain[/url] domain [http://www.example.com link title]
tonypeachey1Nov. 15, 2024, 6:04 a.m.
NSProjectJune 4, 2022, 3:49 a.m.
IscanderCheOct. 31, 2024, 3:43 p.m.
Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…
Добрый день!