2

Is well know qml compiler became available also to open source version for some time now. The procedure for compile qml source is explained here. Is possible to verify that compiler work as expected by checking the generated sources. For example if you have a file named mycode.qml you should find the corresponding .._.._mycode_qml.cpp source (generated by the QML compiler) and relative compiled .obj (on Windows obviously). Explained this, however, I just noticed the (compiled) qml sources code are still clearly visible inside the generated executable (or a .so library in caso of Android compilation) by just using a simple text editor like Notepad++. I suppose because they are integrated as resources but I hope I did something wrong because the usefulness of compiling the qml sources is precisely to hide the code as well as improve performance. Also in the official explanation linked above this should not happen since it says "After activating the Qt Quick Compiler in the build integration, the build system will automatically execute the tool to compile your .qml and .js files into the binary and avoid the inclusion of their source code in the resource system." My environment is Qt version 5.15.2 and Qt Creator version 4.13.2.

test.pro

   QT += quick
    CONFIG += c++11
    SOURCES += \
            main.cpp
    RESOURCES += qml.qrc

qml.qrc

<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
    </qresource>
</RCC>

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    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();
}

main.qml

import QtQuick 2.12
import QtQuick.Window 2.12

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
}

Can anyone help me figure out what I am doing wrong?

Thank you

6
  • "Can anyone help me figure out what I am doing wrong?" -- Well, you haven't described what exactly you are doing, so we can't tell you what's wrong about it. How are you attempting to use the quick compiler? Show your minimal, reproducible example. Commented Dec 8, 2020 at 14:06
  • I'm compiling using Qt Creator with Qt Quick compiler enabled. I create a project following the instruction is the official Qt page linked. I can see the ._.._mycode_qml.cpp source generated by the Qt Quick compiler but I can also found the mycode.qml source inside the generated executable that, based to the information, should not happen. Do I need to provide an example full source project (pro and qml)? Commented Dec 8, 2020 at 14:56
  • Did you read the link? We should be able to reproduce your problem with the info that you provide. I could start questioning you, "Did you do this? Did you forget that line?" But I'd just be guessing. Commented Dec 8, 2020 at 15:05
  • Example project added. If I try to compile I can see in the generated file folder the source main_qml.cpp but inside the executable I can find the source of main.qml also. Commented Dec 8, 2020 at 15:06
  • Your example seems to be missing CONFIG += qtquickcompiler. Commented Dec 8, 2020 at 15:54

1 Answer 1

1

As a workaround we can use

QMAKE_RESOURCE_FLAGS += -threshold 0

for QMake projects. All the files from resources will be compressed and most part of the QML code will be hidden. The reason why all QML files are included to the final executable when QtQuickCompiler is turned on is described here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.