A couple Qt various questions
-
Hi all,
I've got three issues:
-
My Qt Creator icon (on windows desktop) shows 6.0.2 as the version but on the About Qt Creator window, it shows:
Qt Creator 7.0.0
Based on Qt 6.2.3 (MSVC 2019, 64 bit)
What's my Qt Creator version, please? -
In some QML projects where I use a Q_PROPERTY for data members and at times need more methods, I mark them, as expected, Q_INVOKABLE. But it doesn't make any difference and with or without it the project works the same! Why, please? Does that keyword any advantage?
-
In Projects -> Build Android APK -> Create Templates when I click on Finish on the wizard, I get the error: Could not update the project ..., I click on OK and it takes me to the AndroidManifest.qml window. I set the application name to "My Program" and select an icon for the project:
Then I build the project using Android Release mode and install the generated APK file on my Galaxy Samsung S10 virtual device. But neither the project name is what I already set nor is the icon for the program set as expected! :(
Any reason, please? -
-
@qcoderpro said in A couple Qt various questions:
Hi all,
I've got three issues:
- My Qt Creator icon (on windows desktop) shows 6.0.2 as the version but on the About Qt Creator window, it shows:
Qt Creator 7.0.0
Based on Qt 6.2.3 (MSVC 2019, 64 bit)
What's my Qt Creator version, please?
It's 7.0.0.
You can change icon name to anything, it's just a string. But that
About Qt Creator
shows is compiled into the binary at compile time, and so it's always true.- In some QML projects where I use a Q_PROPERTY for data members and at times need more methods, I mark them, as expected, Q_INVOKABLE. But it doesn't make any difference and with or without it the project works the same! Why, please? Does that keyword any advantage?
It should not work the same. A method which is not Q_INVOKABLE and not a slot cannot be invoked through the meta object system (which QML uses).
Perhaps those extra methods you refer to are
slots
? Then it's all good. All slots are Q_INVOKABLE.- In Projects -> Build Android APK -> Create Templates when I click on Finish on the wizard, I get the error: Could not update the project ..., I click on OK and it takes me to the AndroidManifest.qml window. I set the application name to "My Program" and select an icon for the project:
[...]
Then I build the project using Android Release mode and install the generated APK file on my Galaxy Samsung S10 virtual device. But neither the project name is what I already set nor is the icon for the program set as expected! :(
Any reason, please?
Perhaps your project is not set up to use this manifest. See https://doc.qt.io/qt-5/qmake-variable-reference.html#android-package-source-dir if you are using qmake.
- My Qt Creator icon (on windows desktop) shows 6.0.2 as the version but on the About Qt Creator window, it shows:
-
@sierdzio thanks for your reply.
Perhaps those extra methods you refer to are slots? Then it's all good. All slots are Q_INVOKABLE.
Yes, they're slots, public slots. So altogether the keyword Q_INVOKABLE is something trivial. We can never use it.
if you are using qmake
I'm using CMake.
-
@qcoderpro said in A couple Qt various questions:
@sierdzio thanks for your reply.
Perhaps those extra methods you refer to are slots? Then it's all good. All slots are Q_INVOKABLE.
Yes, they're slots, public slots. So altogether the keyword Q_INVOKABLE is something trivial. We can never use it.
If you push all methods you want to invoke to
slots
then yes.It is not trivial though,
slots
andQ_INVOKABLE
adds overhead and more info to the meta object information.if you are using qmake
I'm using CMake.
There is some similar variable for cmake, too. Sorry I can't find it now :(
-
Accessors for Q_PROPERTY (READ & WRITE) don't need to be slots or Q_INVOKABLE to access the property in QML. I'd go as far as to say they shouldn't be.
Just define them in the public scope. -
@qcoderpro said in A couple Qt various questions:
I don't have any use case where it as a new feature is useful.
RETURN VALUES!
If you have a method that has to perform some operation and return a result that's what
Q_INVOKABLE
is for -
If that method returning a value is the getter, we simply define it in the
public
scope - without Q_INVOKABLE.
If that method returning a value is not mentioned in Q_PROPERTY, we simply define it in thepublic slots
and it returns the value without a Q_INVOKABLE. -
Here's a proving example for what I wrote:
.h
file:class SomeClass : public QObject { Q_OBJECT Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged); public: explicit SomeClass(QObject *parent = nullptr); const QString getName() const; void setName(const QString&); signals: void nameChanged(QString); public slots: int numberSquared(int); private: QString name; };
.cpp
file:SomeClass::SomeClass(QObject *parent) : QObject{parent} { } int SomeClass::numberSquared(int n) { return n * n; } const QString SomeClass::getName() const { return name; } void SomeClass::setName(const QString& newName) { if (name != newName) { name = newName; emit nameChanged(name); } }
.qml
file:SomeClass { id: obj } Column { anchors.centerIn: parent Button { text: "test button 1" onClicked: obj.name = text } Button { text: "test button 2" onClicked: text = obj.name } Button { text: "test button 3 " onClicked: text += obj.numberSquared(5) } }
The methods returning a value work as I expected with no Q_INVOKABLE keyword, either in setter/getter or numberSquared.
-
@qcoderpro said in A couple Qt various questions:
If that method returning a value is not mentioned in Q_PROPERTY, we simply define it in the public slots and it returns the value without a Q_INVOKABLE.
Yes you can use
public slots
if you want, my personnal preferrence is to useQ_INVOKABLE
for methods which I want to be accessible from QML.
I found this more readable.