Or, you use something like sed -i "s/unreleased/%{version}/" qml/pages/AboutPage.qml in the .spec file in the %build section, while having “unreleased” as the version string in the source.
Presumably @Edz, like me, is too absent-minded to remember to update the version in multiple places, regardless off which places those are. I don’t think putting it in the .ts helps then, or?
If it’s done like this, does it mean that the version number in qml-pages is updated only if the main.cpp is recompiled? Then if there’s changes in qml-files only, main() would be using APP_VERSION that was valid when main.cpp was compiled last time.
True. But in practice that has not been a problem. When building for release you need to clean up between building for different architectures anyway. And when testing, at least i am not so fussed about having perfect temporary versions.
Thanks for all the input guys, not that I am able to get any of it working. I actually thought going into the idea, that it would be fairly easy to implement…snort!
I mainly played with the code shown by @attah, but have come to the conclusion of “I can no longer be bothered with this idea”.
Perhaps I’ll revisit at some point, but thanks again for input. I do have vague recollection the coderus had made an app with “automagic” for displaying application details in an about page including the version number.
Here’s how I do it in my apps. By building a temporary header file that is included in main.cpp I make sure the version number stays up-to-date even without actual code changes (cf. above).
Define version in yaml and set qmake options (make sure you have Builder: qmake5)
Use this qmake option in pro to pass it to cpp
Expose the values from cpp to qml (or use attah’s way)
Adding it as QMakeOptions in .yaml file as @martyone suggested works perfectly fine and is persistent. I already changed all my projects to use it this way, finally just one place (Version in .yaml) to change the version string, and it is then seen everywhere else, both in C++ and QML.
P.S. What happened to the “Accept as solution” button?