alex_lip16 августа 2018 г. 4:48
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
Рекомендуем хостинг TIMEWEB
Стабильный хостинг, на котором располагается социальная сеть EVILEG. Для проектов на Django рекомендуем VDS хостинг.Вам это нравится? Поделитесь в социальных сетях!
Комментарии
Только авторизованные пользователи могут публиковать комментарии.
Пожалуйста, авторизуйтесь или зарегистрируйтесь
Пожалуйста, авторизуйтесь или зарегистрируйтесь
AD
- Akiv Doros
- 11 ноября 2024 г. 14:58
C++ - Тест 004. Указатели, Массивы и Циклы
- Результат:50баллов,
- Очки рейтинга-4
m
- molni99
- 26 октября 2024 г. 1:37
C++ - Тест 004. Указатели, Массивы и Циклы
- Результат:80баллов,
- Очки рейтинга4
m
- molni99
- 26 октября 2024 г. 1:29
C++ - Тест 004. Указатели, Массивы и Циклы
- Результат:20баллов,
- Очки рейтинга-10
Последние комментарии
Qt/C++ - Урок 031. QCustomPlot - строим график по времени buy generic priligy We can just chat, and we will not lose too much time anyway
Qt/C++ - Урок 060. Настройка внешнего вида приложения в рантайме I didnt have an issue work colors priligy dapoxetine 60mg revia cost uk August 3, 2022 Reply
Коммутация каналов и пакетов в сетях передачи данных Angioedema 1 priligy dapoxetine
Как Копировать Файлы в Linux If only females relatives with DZ offspring were considered these percentages were 23 order priligy online uk
Qt/C++ - Урок 068. Hello World с использованием системы сборки CMAKE в CLion ditropan pristiq dosing With the Yankees leading, 4 3, Rivera jogged in from the bullpen to a standing ovation as he prepared for his final appearance in Chicago buy priligy pakistan
Сейчас обсуждают на форуме
добавить qlineseries в функции priligy amazon canada 93 GREB1 protein GREB1 AB011147 6
Всё ещё разбираюсь с кешем. priligy walgreens levitra dulcolax carbs The third ring was found to be made up of ultra relativistic electrons, which are also present in both the outer and inner rings
IscanderChe31 октября 2024 г. 15:43
Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…
ИМ
Реализация навигации по разделам Спасибо Евгений!
Игорь Максимов3 октября 2024 г. 4:05
Добрый день!