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() を呼び出すとイベントループが開始します。
あるいは、Qt Quick Ultraliteイベントループは、Qul::Application::update()を定期的に呼び出すことで実行されます。
ベアメタル
例えば、QMLで定義されたmain項目が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();
}注: Qul::initPlatform() を呼び出す前に、FreeRTOS Heap_5 を初期化する必要があります。
テキストキャッシュの初期化
ベアメタル
アプリケーション用にテキスト・キャッシュを設定するには、次の例に示すように、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 ライセンスの下で利用可能です。
詳細を確認してください。