Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to open an Android app in a QML app?
Forum Updated to NodeBB v4.3 + New Features

How to open an Android app in a QML app?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
3 Posts 2 Posters 707 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    a.burks
    wrote on 1 Sept 2019, 21:49 last edited by a.burks 9 Feb 2019, 02:33
    #1

    Is it possible to open an Android app with a Qt.openUrlExternally() command, maybe with a specific protocol, or do I have to implement a JNI solution?

    I found a quire old project at GitHub: https://github.com/AndroidCpp/qmlandroidlauncher

    I seem to work, but my app exits, because I seem to make something wrong in the main C++ class.

    The Qt Android app template suggests the following code:

    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
    QGuiApplication app(argc, argv);
    
    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    
    engine.load(url);
    
    return app.exec();
    

    The Github projects uses the following code, wherein I replaced QApplication by QGuiApplication:

    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);
    QQuickView viewer;
    viewer.setResizeMode(QQuickView::SizeRootObjectToView);
    
    BackEnd backend(viewer);
    
    viewer.rootContext()->setContextProperty("backEnd", &backend);
    
    QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close);
    viewer.setSource(QUrl("qrc:/main.qml"));
    viewer.show();
    return app.exec();
    

    The app shows two warning before it is closed:

    QQuickView does not support using windows as a root item.
    If you wish to create your root window from QML, consider using QQmlApplicationEngine instead.
    
    J 1 Reply Last reply 2 Sept 2019, 05:42
    0
    • J J.Hilk
      2 Sept 2019, 05:42

      hi @a-burks
      as far as I know, that is going to require nativ calls, but there is the QtAndroid module
      https://doc.qt.io/qt-5/qtandroid.html

      that allows you to make native calls from qt, easily enough

      A Offline
      A Offline
      a.burks
      wrote on 2 Sept 2019, 07:44 last edited by a.burks 9 Mar 2019, 14:34
      #3

      @j-hilk Thanks. I know the Qt Android Extras. Unfortunately I don't know how to make the C++ class available. I used the quoted approach of the example project, but this causes a conflict with the root QML type ApplicationWindow in my main.qml file.

      Edit: I have now implemented a different approach than the official example of Qt Android Extras: The default integration approach, that is described herer: https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html. This seem to work, but I have to make further tests.

      2nd Edit: Now it works

      1 Reply Last reply
      0
      • A a.burks
        1 Sept 2019, 21:49

        Is it possible to open an Android app with a Qt.openUrlExternally() command, maybe with a specific protocol, or do I have to implement a JNI solution?

        I found a quire old project at GitHub: https://github.com/AndroidCpp/qmlandroidlauncher

        I seem to work, but my app exits, because I seem to make something wrong in the main C++ class.

        The Qt Android app template suggests the following code:

        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        
        QGuiApplication app(argc, argv);
        
        QQmlApplicationEngine engine;
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                         &app, [url](QObject *obj, const QUrl &objUrl) {
            if (!obj && url == objUrl)
                QCoreApplication::exit(-1);
        }, Qt::QueuedConnection);
        
        engine.load(url);
        
        return app.exec();
        

        The Github projects uses the following code, wherein I replaced QApplication by QGuiApplication:

        QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
        QQuickView viewer;
        viewer.setResizeMode(QQuickView::SizeRootObjectToView);
        
        BackEnd backend(viewer);
        
        viewer.rootContext()->setContextProperty("backEnd", &backend);
        
        QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close);
        viewer.setSource(QUrl("qrc:/main.qml"));
        viewer.show();
        return app.exec();
        

        The app shows two warning before it is closed:

        QQuickView does not support using windows as a root item.
        If you wish to create your root window from QML, consider using QQmlApplicationEngine instead.
        
        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 2 Sept 2019, 05:42 last edited by
        #2

        hi @a-burks
        as far as I know, that is going to require nativ calls, but there is the QtAndroid module
        https://doc.qt.io/qt-5/qtandroid.html

        that allows you to make native calls from qt, easily enough


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        A 1 Reply Last reply 2 Sept 2019, 07:44
        0
        • J J.Hilk
          2 Sept 2019, 05:42

          hi @a-burks
          as far as I know, that is going to require nativ calls, but there is the QtAndroid module
          https://doc.qt.io/qt-5/qtandroid.html

          that allows you to make native calls from qt, easily enough

          A Offline
          A Offline
          a.burks
          wrote on 2 Sept 2019, 07:44 last edited by a.burks 9 Mar 2019, 14:34
          #3

          @j-hilk Thanks. I know the Qt Android Extras. Unfortunately I don't know how to make the C++ class available. I used the quoted approach of the example project, but this causes a conflict with the root QML type ApplicationWindow in my main.qml file.

          Edit: I have now implemented a different approach than the official example of Qt Android Extras: The default integration approach, that is described herer: https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html. This seem to work, but I have to make further tests.

          2nd Edit: Now it works

          1 Reply Last reply
          0

          1/3

          1 Sept 2019, 21:49

          • Login

          • Login or register to search.
          1 out of 3
          • First post
            1/3
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved