Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. A couple Qt various questions
Forum Updated to NodeBB v4.3 + New Features

A couple Qt various questions

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
11 Posts 5 Posters 922 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q qcoderpro

    Hi all,

    I've got three issues:

    1. 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?

    2. 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?

    3. 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:

    werwer.PNG

    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?

    sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #2

    @qcoderpro said in A couple Qt various questions:

    Hi all,

    I've got three issues:

    1. 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.

    1. 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.

    1. 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.

    (Z(:^

    Q 1 Reply Last reply
    1
    • sierdzioS sierdzio

      @qcoderpro said in A couple Qt various questions:

      Hi all,

      I've got three issues:

      1. 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.

      1. 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.

      1. 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.

      Q Offline
      Q Offline
      qcoderpro
      wrote on last edited by qcoderpro
      #3

      @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.

      sierdzioS 1 Reply Last reply
      0
      • Q qcoderpro

        @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.

        sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #4

        @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 and Q_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 :(

        (Z(:^

        Q 1 Reply Last reply
        1
        • sierdzioS sierdzio

          @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 and Q_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 :(

          Q Offline
          Q Offline
          qcoderpro
          wrote on last edited by
          #5

          @sierdzio

          Is it the right approach to define the setter and getter in the public scope of the class (not in the public slots) with Q_INVOKABLE, or is it not needed yet?

          1 Reply Last reply
          0
          • GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by GrecKo
            #6

            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.

            1 Reply Last reply
            2
            • Q Offline
              Q Offline
              qcoderpro
              wrote on last edited by
              #7

              I guess the specifier Q_INVOKABLE is redundant likely. I don't have any use case where it as a new feature is useful.

              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #8

                @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

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                Q 1 Reply Last reply
                2
                • VRoninV VRonin

                  @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

                  Q Offline
                  Q Offline
                  qcoderpro
                  wrote on last edited by qcoderpro
                  #9

                  @VRonin

                  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 the public slots and it returns the value without a Q_INVOKABLE.

                  KroMignonK 1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    qcoderpro
                    wrote on last edited by
                    #10

                    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.

                    1 Reply Last reply
                    0
                    • Q qcoderpro

                      @VRonin

                      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 the public slots and it returns the value without a Q_INVOKABLE.

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by
                      #11

                      @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 use Q_INVOKABLE for methods which I want to be accessible from QML.
                      I found this more readable.

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved