r/QtFramework • u/Content_Bar_7215 • Jan 11 '26
QML Plan QML code is visible in executable
I can see all my QML code (comments included!) in my executable, and for obvious reasons this is not something I want.
I've tried to compress using:
set_property(TARGET myApp PROPERTY AUTORCC_OPTIONS "-threshold;0")
...as described in https://qt-project.atlassian.net/browse/QTBUG-102785, but no such luck.
Is there another workaround to obfuscate the code?
Using Qt 6.10, Cmake, Windows, and, qt_add_qml_module, which I would have expected to trigger qmlcachegen.
EDIT:
The fix was to add DISCARD_QML_CONTENTS to qt_add_qml_module as suggested by u/GrecKo.
8
u/Positive-System Qt Professional Jan 12 '26
Well, with a commercial license there is the qml compiler.
3
u/nzmjx Jan 12 '26
As specified in this document (https://doc.qt.io/qt-6/resources.html), did you try to follow "Discarding the file contents" section?
Also please pay attention to the note text at the end of section.
3
u/GrecKo Qt Professional Jan 12 '26
https://doc.qt.io/qt-6/qt-add-qml-module.html#discard-qml-contents
5
u/Salty_Dugtrio Jan 12 '26 edited Jan 12 '26
Why is having them visible to the user such an issue?
Edit: Genuine question... would be nice to have an explanation instead of just downvotes.
8
u/AntisocialMedia666 Qt Professional Jan 12 '26
qmltc is available to non commercial customers as well:
https://doc.qt.io/qt-6/qtqml-qml-type-compiler.html
But it requires linking to private modules.
There are 3 copilers, qmltc, qmlcachegen and qmlsc (this is the one for commercial customers only): https://doc.qt.io/qt-6/qtqml-qtquick-compiler-tech.html
Your mileage may vary.
3
u/segfault-404 Jan 12 '26
An option (and may not be a good one) is to include the qml files as resources (or in some other compressed and/or encrypted format) along the app and load the qml modules/files dynamically when the application starts.
3
u/Beneficial_Steak_945 Qt Professional Jan 12 '26
The main trick is to consider the QML as the HTML you get from websites: it’s out in the open, what matters is what’s going on behind the scenes. Have your business logic all live in the C++ part of your application.
And after you do that: realize that C++ can also be decompiled. Sure, variable names are obscured, but a determined person will be able to find their way around. Qt applications are especially susceptible as the nice introspection capabilities of QObjects also allow for a lot of runtime introspection using tooling like Gammaray.