Armadilloフォーラム

Qt Quick2アプリケーションをatmark-distに統合する方法

amano

2018年3月1日 16時30分

Qt Quick2アプリケーションでビルドした実行ファイルをatmark-distに統合し、実行したところ、

[root@armadillo840-0 (ttySC2) ~]# QT_QPA_EGLFS_DISPLAY=1 QT_QPA_EGLFS_WIDTH=800
QT_QPA_EGLFS_HEIGHT=480 LANG=ja_JP.UTF-8 /mnt/test_AM2/test_AM2 -plugin evdevtou
ch:/dev/input/event2
evdevtouch: Using device /dev/input/event0
min X: 0 max X: 799
min Y: 0 max Y: 479
min pressure: 0 max pressure: 0
device name: st1232-touchscreen
Protocol type B (mtdev)
evdevtouch: Using device /dev/input/event2
min X: 0 max X: 4095
min Y: 0 max Y: 4095
min pressure: 0 max pressure: 0
device name: MITSUBISHI ELECTRIC USB Touch
Protocol type B (mtdev)
file:///root/qml/test_AM2/main.qml: File not found
となり、QMLファイルを実行できません。

Qt Quick2アプリケーションをatmark-distに統合し、実行する手順を教えてください。

目的としては
C++とQMLの使用したアプリケーションを作成するため、
まずは「Hello World」を表示させてみようと思いました。

私が実施した手順
1、Qt Createrにて「プロジェクトを作成」→「アプリケーション」→「Qt Quick2アプリケーション」を
選択してプロジェクトを作成(プロジェクト名test_AM2)
ソース変更なし(Hello Worldのまま)
デスクトップ上で実行できることを確認
キットをArmadilloにしてリビルド
test_AM2ディレクトリをatmark-dist/user/qt5/以下へコピー

2、test_AM.proを変更
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()

INSTALLS += target ←追加
target.path = /usr/bin ←追加

3、/atmark-dist/user/qt5/Makefile変更
subdir_y = qmlscene
subdir_y += test_AM2 ←追加
subdir_y += hello-qt
qmldir_y += test_AM2/qml ←追加
qmldir_y += hello_qml
qmldir_$(CONFIG_USER_QT5_PHOTOVIEWER) += photoviewer

4、atmark-dist/user/qt5/test_AM2/qml/Makefile作成

all:
#nothing to do here

romfs install_target:
mkdir -p $(ROMFSDIR)/usr/bin/qml
$(ROMFSINST) test_AM2 \
/usr/bin/qml/test_AM2

以上

実行すると真っ白画面になります。「Hello World」の文字が表示しません。
main.cのviewer.setMainQmlFile(QStringLiteral("qml/test_AM2/main.qml"));
を変更する必要があるのでしょうか。

ちなみに
QT_QPA_EGLFS_DISPLAY=1 QT_QPA_EGLFS_WIDTH=800
QT_QPA_EGLFS_HEIGHT=480 qmlscene /usr/bin/qml/test_AM2/main.qml -plugin evdevto
uch:/dev/input/event2
は「Hello World」と表示します。

コメント

at_ohsawa

2018年3月12日 13時52分

> 実行すると真っ白画面になります。「Hello World」の文字が表示しません。
> main.cのviewer.setMainQmlFile(QStringLiteral("qml/test_AM2/main.qml"));
> を変更する必要があるのでしょうか。

viewer.setSource(QUrl("qrc:/qml/test_AM2/main.qml"));

と書いたらどうなりますか。

amano

2018年3月13日 14時34分

ご回答ありがとうございます。

試してみましたが、できませんでした。
以下のが返ってきます。

[root@armadillo840-0 (ttySC2) ~]# QT_QPA_EGLFS_DISPLAY=1 QT_QPA_EGLFS_WIDTH=800 
QT_QPA_EGLFS_HEIGHT=480 LANG=ja_JP.UTF-8 /mnt/test_AM2/test_AM2 -plugin evdevtou
ch:/dev/input/event2                                                            
evdevtouch: Using device /dev/input/event0                                      
min X: 0 max X: 799                                                             
min Y: 0 max Y: 479                                                             
min pressure: 0 max pressure: 0                                                 
device name: st1232-touchscreen                                                 
Protocol type B (mtdev)                                                         
evdevtouch: Using device /dev/input/event2                                      
min X: 0 max X: 4095                                                            
min Y: 0 max Y: 4095                                                            
min pressure: 0 max pressure: 0                                                 
device name: MITSUBISHI ELECTRIC USB Touch                                      
Protocol type B (mtdev)                                                         
qrc:/qml/test_AM2/test_AM.qml: File not found

※main.qmlはtest_AM2.qmlに変わりました。

ちなみに以下の方法で実行は可能になりました。

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
 
    QtQuick2ApplicationViewer viewer;
    // デスクトップ上
    //viewer.setMainQmlFile(QStringLiteral("qml/test_AM2/test_AM.qml"));
    // Armadillo(SDデバッグ)
    //viewer.setMainQmlFile("/mnt/test_AM2/qml/test_AM2/test_AM.qml");
    // Armadillo(統合)
    viewer.setMainQmlFile("/usr/bin/qml/test_AM2/test_AM.qml");
    // 問い合わせ回答
    //viewer.setSource(QUrl("qrc:/qml/test_AM2/test_AM.qml"));
 
 
    viewer.showExpanded();
 
    ---省略---
 
    return app.exec();
}

ただこの場合だと実行環境によってソースを変更する必要があります。
環境に影響しない方法はございますでしょうか。

at_kojiro.yamada

2018年3月13日 19時17分

あまりスマートではないですが、
QFile クラスでqmlファイルが配置される可能性のあるパスをチェックし、qmlファ
イルがあるパスに対してだけ、setMainQmlFileを実行するのはどうでしょうか?

以下のようなイメージです。

    QGuiApplication app(argc, argv);
 
    QtQuick2ApplicationViewer viewer;
    // デスクトップ上
    if (QFile(QStringLiteral("qml/test_AM2/test_AM.qml")).exists)
        viewer.setMainQmlFile(QStringLiteral("qml/test_AM2/test_AM.qml"));
    // Armadillo(SDデバッグ)
    else if (QFile(QStringLiteral("/mnt/test_AM2/qml/test_AM2/test_AM.qml")).exists)
        viewer.setMainQmlFile("/mnt/test_AM2/qml/test_AM2/test_AM.qml");
    // Armadillo(統合)
     : 略