C
Entry point to Qt Quick Ultralite application
Initializing Qt Quick Ultralite from main()
It's up to application developer on how and when hardware initialization is done. Typically it's done by calling Qul::initHardware() just before Qul::initPlatform(), but developer may also decide not call it and perform own hardware initialization.
To start the graphical part of your application you need to call Qul::initPlatform(), create a Qul::Application object in your main() or a task function and then call the Qul::Application::exec() function.
Qul::initPlatform() initializes Qt Quick Ultralite platform components and the event loop starts when you call Qul::Application::exec().
For example, if the main item defined in QML is called MainScreen, main.cpp on bare metal could contain the following:
#include "MainScreen.h" #include <qul/application.h> #include <qul/qul.h> int main() { Qul::initHardware(); Qul::initPlatform(); Qul::Application app; static MainScreen item; app.setRootItem(&item); while (true) { uint64_t now = Qul::Platform::getPlatformInstance()->currentTimestamp(); // <handle timers> uint64_t nextUpdate = app.update(); if (nextUpdate > now) { // Device can go to sleep until next update is due // enterLowPowerMode(nextUpdate - now); } } return 1; }
Or when using FreeRTOS main.cpp could be:
#include "MainScreen.h" #include <qul/application.h> #include <qul/qul.h> #include <platforminterface/log.h> #include <FreeRTOS.h> #include <task.h> #ifndef QUL_STACK_SIZE #error QUL_STACK_SIZE must be defined. #endif static void Qul_Thread(void *argument); // extern const HeapRegion_t xHeapRegions[]; // HeapRegion for FreeRTOS Heap_5 int main() { Qul::initHardware(); // vPortDefineHeapRegions(xHeapRegions); // Initialize FreeRTOS Heap_5 Qul::initPlatform(); if (xTaskCreate(Qul_Thread, "QulExec", QUL_STACK_SIZE, 0, 4, 0) != pdPASS) { Qul::PlatformInterface::log("Task creation failed!.\r\n"); configASSERT(false); } vTaskStartScheduler(); // Should not reach this point return 1; } static void Qul_Thread(void *argument) { Qul::Application app; static MainScreen item; app.setRootItem(&item); while (true) app.update(); }
Note: FreeRTOS Heap_5 must be initialized before calling Qul::initPlatform().
To configure text cache for your application, call the appropriate Qul::Application constructor in main.app
, as shown in the following example:
#include "MainScreen.h" #include <qul/application.h> #include <qul/qul.h> int main() { Qul::initHardware(); Qul::initPlatform(); Qul::ApplicationConfiguration appConfig; appConfig.setTextCacheEnabled(true); appConfig.setTextCacheSize(128 * 1024); Qul::Application app(appConfig); static MainScreen item; app.setRootItem(&item); while (true) { uint64_t now = Qul::Platform::getPlatformInstance()->currentTimestamp(); // <handle timers> uint64_t nextUpdate = app.update(); if (nextUpdate > now) { // Device can go to sleep until next update is due // enterLowPowerMode(nextUpdate - now); } } return 1; }
And, similarly for FreeRTOS:
#include "MainScreen.h" #include <qul/application.h> #include <qul/qul.h> #include <platforminterface/log.h> #include <FreeRTOS.h> #include <task.h> #ifndef QUL_STACK_SIZE #error QUL_STACK_SIZE must be defined. #endif static void Qul_Thread(void *argument); // extern const HeapRegion_t xHeapRegions[]; // HeapRegion for FreeRTOS Heap_5 int main() { Qul::initHardware(); // vPortDefineHeapRegions(xHeapRegions); // Initialize FreeRTOS Heap_5 Qul::initPlatform(); if (xTaskCreate(Qul_Thread, "QulExec", QUL_STACK_SIZE, 0, 4, 0) != pdPASS) { Qul::PlatformInterface::log("Task creation failed!.\r\n"); configASSERT(false); } vTaskStartScheduler(); // Should not reach this point return 1; } static void Qul_Thread(void *argument) { Qul::ApplicationConfiguration appConfig; appConfig.setTextCacheEnabled(true); appConfig.setTextCacheSize(64 * 1024); Qul::Application app(appConfig); static MainScreen item; app.setRootItem(&item); while (true) app.update(); }
Available under certain Qt licenses.
Find out more.