Hmm, yes… too much of an oversimplification.
You might need to do the “complicated” version of the app launch…
See here:
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.
Maybe a “cheating” way of doing it, and not quite correct… But if you translate your apps you could have the version number in your .ts file
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?
Would not the original language be a fallback when the string is not translated in $whatever
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.
It turns out that in addition to what @attah wrote above, it also takes adding the following to the .spec file:
VERSION=%{version}
as in https://github.com/attah/harbour-seaprint/blob/master/rpm/harbour-seaprint.spec
Then it works OK. But it is annoying like hell, because everytime the spec file gets automatically updated it obviously gets removed.
Anyone knows if/how it can be added to the .yaml file instead, so that it just stays there?
Put it in the perstistent sections in the spec, something like
# >> build pre
export CFLAGS="-DVERSION=%{version}"
# << build pre
Or depending on your configurer use something like CMAKE_EXTRA_CFLAGS or the qmake equivalent.
Maybe:
Version: %{version}
will work? It should generate VERSION=… in spec
Yes:
QMakeOptions:
- VERSION=%{version}
All available directives are listed here https://github.com/sailfishos/spectacle.
Just to add one more hint, if you have spectacle installed, the README is also available locally at /usr/share/doc/spectacle-0.32/README.md
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 haveBuilder: qmake5
)
- Use this qmake option in
pro
to pass it tocpp
- Expose the values from
cpp
toqml
(or use attah’s way)
- Finally use it in
AboutPage.qml
By including the helper pri
file in the pro
file my temporary header file gets updated when qmake
is run.
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?
I think it’s available only to the OP.
Ah, right
I do it very similar but extract the from the rpm spec file that is update with the latest tag during build.
They way I do is but using QMake to substitute some variables in my data class that is then compiled in:
To pass those values to qmake I call rpmspec during build to parse the specfile with this small qmake function:
When all this assembled the class is build from where it is available on the C++ and QML side: