On this page

C

Running Qt Quick Ultralite in applications

Startup and entering into the Qt Quick Ultralite event loop

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 drive the event loop by calling Qul::Application::update() and Qul::Application::waitUntil() in a loop:

while (true) {
    const uint64_t nextUpdate = app.update();
    app.waitUntil(nextUpdate);
}

Qul::Application::update() updates the Qt Quick Ultralite core engine once and returns the timestamp when it should be called next. Qul::Application::waitUntil() suspends until that timestamp passes, or until an event, such as a touch event, resumes it early.

Bare metal

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>

#include <cstdint>

int main()
{
    Qul::initHardware();
    Qul::initPlatform();
    Qul::Application app;
    static MainScreen item;
    app.setRootItem(&item);
    while (true) {
        const uint64_t nextUpdate = app.update();
        app.waitUntil(nextUpdate);
    }
    return 1;
}

FreeRTOS

Main.cpp example:

#include "MainScreen.h"

#include <qul/application.h>
#include <qul/qul.h>
#include <platforminterface/log.h>

#include <FreeRTOS.h>
#include <task.h>

#include <cstdint>

#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) {
        const uint64_t nextUpdate = app.update();
        app.waitUntil(nextUpdate);
    }
}

Note: FreeRTOS Heap_5 must be initialized before calling Qul::initPlatform().

Available under certain Qt licenses.
Find out more.