C
アプリケーション内でのQt Quick Ultraliteの実行
起動とQt Quick Ultraliteのイベントループへの移行
ハードウェアの初期化をいつ、どのように行うかは、アプリケーション開発者に委ねられています。通常は、Qul::initPlatform() の直前にQul::initHardware() を呼び出すことで行われますが、開発者はこれを呼び出さず、独自のハードウェア初期化を行うことも可能です。
アプリケーションのグラフィカルな部分を起動するには、Qul::initPlatform()を呼び出し、main()またはタスク関数内でQul::Application オブジェクトを作成し、その後Qul::Application::exec()関数を呼び出す必要があります。
Qul::initPlatform() はQt Quick Ultralite プラットフォームのコンポーネントを初期化し、Qul::Application::exec() を呼び出すとイベントループが開始されます。
あるいは、Qul::Application::update() を定期的に呼び出すことで、Qt Quick Ultralite のイベントループを実行することもできます。
ベアメタル
たとえば、QML で定義されたメイン項目が MainScreen である場合、ベアメタル上の main.cpp には次のようなコードが含まれることになります。
#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;
}FreeRTOS
main.cpp の例:
#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();
}注: FreeRTOS Heap_5 は、Qul::initPlatform() を呼び出す前に初期化する必要があります。
テキストキャッシュの初期化
ベアメタル
アプリケーションのテキストキャッシュを設定するには、次の例に示すように、main.app 内で適切なQul::Application コンストラクタを呼び出します。
#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;
}FreeRTOS
Main.cpp の例:
#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();
}特定の Qt ライセンスの下で利用可能です。
詳細はこちらをご覧ください。