alex_lip
alex_lip16. August 2018 04: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.
====================================================================================

Питон у меня установлен - но как запустить локальный SimpleHTTPServer - я не понимаю -
когда я пишу в командной строке
C:\qt_buy> python -m SimpleHTTPServer 8080
- ругается -
C:\Python35\python.exe: No module named SimpleHTTPServer





Рекомендуємо хостинг TIMEWEB
Рекомендуємо хостинг TIMEWEB
Stabiles Hosting des sozialen Netzwerks EVILEG. Wir empfehlen VDS-Hosting für Django-Projekte.

Magst du es? In sozialen Netzwerken teilen!

2
Evgenii Legotckoi
  • 23. August 2018 03:06

Добрый день!

Поздновато, конечно, но тем не менее (я в отпуске был, через неделю проджолжение отпуска будет)
Вроде как этот модуль был влит в другой модуль в третьем питоне. Должен так запускаться
$python3 -m http.server 9000



    alex_lip
    • 23. August 2018 07:30
    • Die Antwort wurde als Lösung markiert.
    Странно - у меня он тоже запустился
    python -m http.server 9000
    - видимо название поменялось - в книжке  - SimpleHTTPServer
    Спасибо!

      Kommentare

      Nur autorisierte Benutzer können Kommentare posten.
      Bitte Anmelden oder Registrieren
      Letzte Kommentare
      A
      ALO1ZE19. Oktober 2024 08:19
      Fb3-Dateileser auf Qt Creator Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
      ИМ
      Игорь Максимов5. Oktober 2024 07:51
      Django – Lektion 064. So schreiben Sie eine Python-Markdown-Erweiterung Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
      d
      dblas55. Juli 2024 11:02
      QML - Lektion 016. SQLite-Datenbank und das Arbeiten damit in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
      k
      kmssr8. Februar 2024 18:43
      Qt Linux - Lektion 001. Autorun Qt-Anwendung unter Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
      Qt WinAPI - Lektion 007. Arbeiten mit ICMP-Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
      Jetzt im Forum diskutieren
      J
      JacobFib17. Oktober 2024 03:27
      добавить qlineseries в функции Пользователь может получить любые разъяснения по интересующим вопросам, касающимся обработки его персональных данных, обратившись к Оператору с помощью электронной почты https://topdecorpro.ru…
      JW
      Jhon Wick1. Oktober 2024 15:52
      Indian Food Restaurant In Columbus OH| Layla’s Kitchen Indian Restaurant If you're looking for a truly authentic https://www.laylaskitchenrestaurantohio.com/ , Layla’s Kitchen Indian Restaurant is your go-to destination. Located at 6152 Cleveland Ave, Colu…
      КГ
      Кирилл Гусарев27. September 2024 09:09
      Не запускается программа на Qt: точка входа в процедуру не найдена в библиотеке DLL Написал программу на C++ Qt в Qt Creator, сбилдил Release с помощью MinGW 64-bit, бинарнику напихал dll-ки с помощью windeployqt.exe. При попытке запуска моей сбилженной программы выдаёт три оши…
      F
      Fynjy22. Juli 2024 04:15
      при создании qml проекта Kits есть но недоступны для выбора Поставил Qt Creator 11.0.2. Qt 6.4.3 При создании проекта Qml не могу выбрать Kits, они все недоступны, хотя настроены и при создании обычного Qt Widget приложения их можно выбрать. В чем может …

      Folgen Sie uns in sozialen Netzwerken