Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Q_PROPERTY NOTIFY
Forum Updated to NodeBB v4.3 + New Features

Q_PROPERTY NOTIFY

Scheduled Pinned Locked Moved General and Desktop
11 Posts 6 Posters 13.8k Views 1 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.
  • R Offline
    R Offline
    redlars
    wrote on last edited by
    #1

    Using Qt 4.7.1

    Compiling this code generates the following error: NOTIFY signal 'ValueChanged' of property 'MyValue' does not exist in class MyWidget.
    @
    class MyWidget : public MyBaseWidget, public QAxBindable
    {
    Q_OBJECT
    Q_PROPERTY(int MyValue READ getValue NOTIFY ValueChanged)

    public:
    MyWidget( QWidget *parent = 0, Qt::WindowFlags f = 0 );

    //signals:
    //void ValueChanged(int);
    };
    @

    Both the getValue method and ValueChanged signal are located in the base class.

    Removing the slashes from the two last line makes the code compile.

    Does Q_PROPERTY NOTIFY support using signals located in a base class? If no, are there any plans to add support and should the documentation (1) inform the developer of this limitation?

    (1) - http://doc.qt.nokia.com/4.7-snapshot/properties.html

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Not sure I ever ran into this. Have you tried using:
      @
      Q_PROPERTY(int MyValue READ getValue NOTIFY MyBaseWidget::ValueChanged)
      @

      I am almost certain it will NOT work, but it's still worth a try.

      (Z(:^

      1 Reply Last reply
      0
      • R Offline
        R Offline
        redlars
        wrote on last edited by
        #3

        Thank you for the prompt reply.

        Unfortunately it did not work. The meta-object compiler produced a parser error at MyBaseWidget on the modified Q_PROPERTY line.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          While I think your question is very good, I fail to see a good use case for it. What do you need this functionality for? I think the three (getter, setter, notifyer, and possibly re-setter) are intimately tied together. In what case do you define them in different places in the hierarchy?

          1 Reply Last reply
          0
          • R Offline
            R Offline
            redlars
            wrote on last edited by
            #5

            We have stable widget implementation with a number of methods and signals.
            @
            class MyWidget : public Widget
            {
            Q_OBJECT
            public:
            MyWidget(QWidget* parent = 0, Qt::WindowsFlags f = 0);
            virtual ~MyWidget();

            void setFoo(int);
            int getFoo();

            signals:
            void fooChanged(int);
            };
            @

            At some point we needed to use this widget as an activeX (or activeQt) so we added the class below which did the trick. The Q_PROPERTY attributes act as an interface, therefore it made sense to have it as part of the MyWidgetActiveX class. Recently we used the NOTIFY attribute and discovered that it did not work like READ and WRITE attributes.
            @
            class MyWidgetActiveX : public MyWidget, public QAxBindable
            {
            Q_OBJECT
            Q_PROPERTY(int MyValue READ getFoo WRITE setFoo)

            public:
            MyWidgetActiveX(QWidget* parent = 0, Qt::WindowsFlags f = 0);
            virtual ~MyWidgetActiveX();
            };
            @

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Hmmm... OK. That is interesting. My first feeling would be: add the Q_PROPERTY to the MyWidget class instead. But if that's not possible...

              1 Reply Last reply
              0
              • F Offline
                F Offline
                fcrochik
                wrote on last edited by
                #7

                You can just create a new signal on your MyWidget class (e.g. ValueChanged2), use it on the Q_PROPERTY declaration and on the class constructor connect the baseclass signal (ValueChanged) to the new signal...

                It is not "ideal" but it should work...

                Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  redlars
                  wrote on last edited by
                  #8

                  andre: Agree, probably best solution. Will look into if that is possible in this case. Still find the limitation on NOTIFY strange given READ and WRITE do not have the limitation. Is there a technical reason for this?

                  fcrochik: Agree, works but not ideal.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    ken536
                    wrote on last edited by
                    #9

                    Just is case:
                    Did you define getValue?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      Yes, he did. See code sample above. It has been defined in the base class.

                      I think you should file a bugreport against moc on this. I don't see why for the getter and setter using the implementation in the base class is allowed, but not for the signal.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        alexisdm
                        wrote on last edited by
                        #11

                        [quote author="redlars" date="1335443671"]Is there a technical reason for this?[/quote]
                        If you look at the code generated by the moc, you'll see that there is only two changes when you add a NOTIFY field:

                        • the property flag changes
                        • the index of the notification signal is added to the meta data array.

                        Since the moc doesn't really know which class your class inherits from, it can't know the index of that signal in the base class. The existence of the signal would have to be tested dynamically at runtime rather than at compile time.

                        For the READ and WRITE fields, as the function names are used as is in the generated code, if the functions don't exist, the compiler will generate an error, so the moc doesn't have to do that check itself.

                        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