Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Static library does not work on iOS
Forum Updated to NodeBB v4.3 + New Features

Static library does not work on iOS

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 377 Views 1 Watching
  • 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.
  • C Offline
    C Offline
    cuongkjm
    wrote on last edited by cuongkjm
    #1

    This is my project structure:
    _TestQtSubDir.pro
    ___TestQtQuick.pro
    ___TestQtQuickStatic.pro

    TestQtSubDir.pro

    TEMPLATE = subdirs
    
    SUBDIRS += \
        TestQtQuick \
        TestQtQuickStatic
    
    TestQtQuick.depends = TestQtQuickStatic
    

    "TestQtQuickStatic.pro" is a static library

    QT += quick
    
    TEMPLATE = lib
    CONFIG += staticlib
    
    CONFIG += c++17
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
        TestQtQuickStatic.cpp
    
    HEADERS += \
        TestQtQuickStatic.h
    
    RESOURCES += qml.qrc
    
    # Additional import path used to resolve QML modules in Qt Creator's code model
    QML_IMPORT_PATH =
    
    # Additional import path used to resolve QML modules just for Qt Quick Designer
    QML_DESIGNER_IMPORT_PATH =
    
    # Default rules for deployment.
    unix {
        target.path = $$[QT_INSTALL_PLUGINS]/generic
    }
    !isEmpty(target.path): INSTALLS += target
    

    TestQtQuickStatic.h

    #ifndef TESTQTQUICKSTATIC_H
    #define TESTQTQUICKSTATIC_H
    
    #include <QQmlApplicationEngine>
    
    class TestQtQuickStatic
    {
    public:
    
        static TestQtQuickStatic* instance();
        void load_main_qml();
    
    private:
        TestQtQuickStatic();
    
    private:
        static TestQtQuickStatic* m_instance;
        QQmlApplicationEngine m_engine;
    };
    
    #endif // TESTQTQUICKSTATIC_H
    

    TestQtQuickStatic.cpp

    #include "TestQtQuickStatic.h"
    
    TestQtQuickStatic* TestQtQuickStatic::m_instance = nullptr;
    
    TestQtQuickStatic::TestQtQuickStatic()
    {
    }
    
    TestQtQuickStatic *TestQtQuickStatic::instance()
    {
        if (!m_instance)
            m_instance = new TestQtQuickStatic();
        return m_instance;
    }
    
    void TestQtQuickStatic::load_main_qml()
    {
        const QUrl url(QStringLiteral("qrc:/main.qml"));
        m_engine.load(url);
    }
    

    main.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Text {
            id: name
            text: qsTr("Hello World")
            anchors.centerIn: parent
        }
    }
    

    TestQtQuick.pro is executable:

    QT += quick
    
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
            main.cpp
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    INCLUDEPATH += $$PWD/../TestQtQuickStatic
    
    LIBS += -L$$OUT_PWD/../TestQtQuickStatic -lTestQtQuickStatic
    

    main.cpp

    #include <QGuiApplication>
    #include "TestQtQuickStatic.h"
    
    int main(int argc, char *argv[])
    {
    #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    #endif
    
        Q_INIT_RESOURCE(qml);
    
        QGuiApplication app(argc, argv);
        TestQtQuickStatic::instance()->load_main_qml();
        return app.exec();
    }
    

    The application works ok on Windows and MacOS. But iOS show the following error:

    QQmlApplicationEngine failed to load component
    qrc:/main.qml:2:1: module "QtQuick.Window" is not installed
    qrc:/main.qml:1:1: module "QtQuick" is not installed
    qrc:/main.qml:2:1: module "QtQuick.Window" is not installed
    qrc:/main.qml:1:1: module "QtQuick" is not installed
    

    I am using Qt 5.15.2, MacOS Catalina, Xcode 12.4
    What did i miss?

    1 Reply Last reply
    1
    • KH-219DesignK Offline
      KH-219DesignK Offline
      KH-219Design
      wrote on last edited by
      #2

      It has been several years since I have targeted the iOS platform, but you might be able to find some hints by looking through a template project maintained by me and my co-workers.

      Github Actions are supplying this project with Continuous Integration builds. You can check the actions and see that indeed our project successfully builds for iOS (although this does not prove that it launches on iOS, but I am confident that it does).

      https://github.com/219-design/qt-qml-project-template-with-ci

      (caveat: the project uses Xcode 11)

      Perhaps more interesting is to simply look at the changes we made to our project in order to support iOS:

      https://github.com/219-design/qt-qml-project-template-with-ci/pull/34

      https://github.com/219-design/qt-qml-project-template-with-ci/pull/35

      ... actually... as I look back over those changes, I see that what you are likely missing is this special addition:

      https://github.com/219-design/qt-qml-project-template-with-ci/blob/master/src/app/imports.qml

      www.219design.com
      Software | Electrical | Mechanical | Product Design

      C 1 Reply Last reply
      1
      • KH-219DesignK KH-219Design

        It has been several years since I have targeted the iOS platform, but you might be able to find some hints by looking through a template project maintained by me and my co-workers.

        Github Actions are supplying this project with Continuous Integration builds. You can check the actions and see that indeed our project successfully builds for iOS (although this does not prove that it launches on iOS, but I am confident that it does).

        https://github.com/219-design/qt-qml-project-template-with-ci

        (caveat: the project uses Xcode 11)

        Perhaps more interesting is to simply look at the changes we made to our project in order to support iOS:

        https://github.com/219-design/qt-qml-project-template-with-ci/pull/34

        https://github.com/219-design/qt-qml-project-template-with-ci/pull/35

        ... actually... as I look back over those changes, I see that what you are likely missing is this special addition:

        https://github.com/219-design/qt-qml-project-template-with-ci/blob/master/src/app/imports.qml

        C Offline
        C Offline
        cuongkjm
        wrote on last edited by
        #3

        @KH-219Design thank you so much, you save my day.
        I add a "Imports.qml" to executable project with these import:

        import QtQuick 2.15
        import QtQuick.Window 2.15
        
        QtObject {}
        
        1 Reply Last reply
        0

        • Login

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