[Qbs] QML import issue on iOS

Frank Kuhn frank.kuhn at bee360.com
Wed Jun 22 17:12:42 CEST 2022


Hi there,

I hope this is the right place to post this question to.

We are using Qt 6.2.4 with qbs 1.22.1. We recently moved some platform-dependent implementations from our app into a separate library, which is linked statically on iOS. The implementation depends on QtWebView on iOS. Only the library’s QML files import QtWebView. When running the app, we get the error
> module "QtWebView" is not installed’
This looks like the import within the library is not correctly recognized by qbs. Qt support suggested that this is not possible when the import is in a library and to add a dummy QML file (which basically only contains the “import QtWebView” statement) to the app itself as a workaround, but I wonder if there is a “right” way to do this with qbs or if this even can be considered a qbs bug?

Does anyone know if this should work or if there is something that needs to be done specifically to make this work for imports only present in a (static) library on iOS? On the other platforms we use the <os>deployqt tools and specify a path where all relevant files are present, so it’s only an issue on iOS for us.

I’ve created a small standalone project that reproduces the issue, which I could provide as a zip, but I’m not sure if it’s ok to spam everyone with zip files or if they even go through here, so I’ll add the relevant passages in here:


Project’s qbs file:

import qbs
import qbs.FileInfo

Project {
        references: [
               "testlib/testlib.qbs",
        ]


        CppApplication {

               consoleApplication: false

               name: "QtWebviewLibTest"
               property pathList qmlImportPaths: [
                       FileInfo.joinPaths( project.path, 'qml' ),
               ]

               Depends { name: "Qt.quick" }
               Depends { name: "Qt.quickcontrols2" }
               Depends { name: "bundle" }
               Depends { name: "testlib" }

               cpp.cxxLanguageVersion: ["c++17"]
               cpp.includePaths: [ ".", "testlib" ]
               cpp.libraryPaths: [ "testlib" ]

               Group {
                       name:"Sources (C++)"
                       files: [
                               "main.cpp",
                       ]
               }

               Group {
                       qbs.installPrefix: ""
                       qbs.installDir: "bin"
                       qbs.install: true
                       fileTagsFilter: [ "application" ]
               }


               Group {
                       name: "Sources (QML)"
                       fileTags: qbs.buildVariant === "release" || qbs.targetOS.contains("ios") ? ["qt.core.resource_data"] : []
                       overrideTags: false
                       prefix: "qml/"
                       Qt.core.resourcePrefix: '/' + prefix
                       files: [
                               "main.qml",
                       ]

//                     Group {
//                             name: "WebView iOS dummy import file"
//                             condition: qbs.targetOS.contains("ios")
//                             prefix: parent.prefix + "ios/"
//                             qbs.installDir: "bin/" + prefix
//                             Qt.core.resourcePrefix: '/' + prefix
//                             overrideTags: false
//                             files: [
//                                    "ImportQtWebView.qml",
//                             ]
//                     }

                       Properties {
                               qbs.installPrefix: ""
                               qbs.install: true
                               qbs.installDir: "bin/qml"
                       }

               }
        }
}


Testlib qbs file:


import qbs

import qbs.FileInfo



Product {

        name: "testlib"

        version: "1.0.0"



        property bool forceStaticBuild: qbs.targetOS.contains("ios")

        property pathList qmlImportPaths: [FileInfo.joinPaths( project.path, 'qml' )]

        property bool qmlAsResources: forceStaticBuild || qbs.buildVariant === "release"



        type: {

               var result = forceStaticBuild ? ["staticlibrary"] : ["dynamiclibrary"];

               if(bundle.isBundle)

                       result = result.uniqueConcat(["bundle.content"]);

               return result;

        }



        Export {

               Depends { name: "cpp" }

               cpp.includePaths: [ path ]

               cpp.rpaths: [  FileInfo.joinPaths( product.qbs.installRoot, "lib" ) ]



               Depends {

                       condition: qbs.targetOS.contains("ios")

                       name: "Qt.webview"

               }

        }



        Depends { name: "bundle" }

        Depends { name: "Qt.qml" }



        bundle.isBundle: qbs.targetOS.contains("macos") // No bundle on iOS



        Properties {

               condition: qbs.targetOS.contains("macos")

               bundle.identifierPrefix: "com.bee360"

        }



        Depends {

               condition: qbs.targetOS.contains("macos")

               name: "Qt.webenginecore"

        }

        Depends {

               condition: qbs.targetOS.contains("macos")

               name: "Qt.webenginequick"

        }

        Depends {

               condition: qbs.targetOS.contains("ios")

               name: "Qt.webview"

        }

        Properties {

               condition: qbs.targetOS.contains("ios")

               cpp.frameworks: ["WebKit"]

        }



        cpp.cxxLanguageVersion: "c++17"

        cpp.defines: [

               "QT_DEPRECATED_WARNINGS",

               "TESTLIB_BUILD",

               qmlAsResources ? "TESTLIB_BUILTINRESOURCES" : "TESTLIB_BUNDLESRESOURCES"

        ]



        cpp.includePaths: [

               path

        ]

        cpp.rpaths: [ product.qbs.installRoot + "/lib" ]



        qbs.installDir: "lib"

        qbs.install: true

        qbs.installPrefix: ""

        Qt.qml.importName: "testlib"

        Qt.qml.importVersion: "1.0"



        Group {

               name: "Global"

               files: [

                       "testlib.cpp",

                       "testlib.h",

               ]

        }



        Group {

               name: "WebView (QML)"

               fileTags: qmlAsResources ? ["qt.core.resource_data"] : []

               overrideTags: false

               prefix: "qml/"

               Qt.core.resourcePrefix: '/' + prefix



               Properties {

                       qbs.installPrefix: ""

                       qbs.install: true

                       qbs.installDir: "bin/qml"

               }



               Group {

                       condition: qbs.targetOS.contains( "ios" )



                       name: "WebView (iOS)"

                       prefix: parent.prefix + "ios/"

                       qbs.installDir: "bin/qml/testlib"

                       Qt.core.resourcePrefix: '/qml/testlib'

                       overrideTags: false

                       files: [

                               "WebView.qml",

                               "qmldir",

                       ]

               }



               Group {

                       condition: qbs.targetOS.contains( "macos" )



                       name: "WebView (macos)"

                       prefix: parent.prefix + "macos/"

                       qbs.installDir: "bin/qml/testlib"

                       Qt.core.resourcePrefix: '/qml/testlib'

                       overrideTags: false

                       files: [

                               "WebView.qml",

                               "qmldir",

                       ]

               }

        }

}


The main.qml contains a testlib.WebView and the testlib’s WebView.qml contains the ‘import QtWebView‘ statement.

Thanks in advance for any help & kind regards
Frank



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20220622/1878a31f/attachment-0001.htm>


More information about the Qbs mailing list