Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-115630

Qt D-Bus: Document that users should not mix Q_PROPERTY and Q_SLOTS

    XMLWordPrintable

Details

    Description

      Below is valid Qt C++ code. However, trying to expose this to D-Bus using qdbuscpp2xml/qdbusxml2cpp might cause problems (see QTBUG-115629 ): setValue() might be exposed twice: Once as a D-Bus Property setter, and once as a D-Bus Method.

       

      Code
      Adapted from the example at https://doc.qt.io/qt-6/signalsandslots.html

      // counter.h
      #ifndef COUNTER_H
      #define COUNTER_H
      #include <QObject>
      
      class Counter : public QObject
      {
          Q_OBJECT
          Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged);
      
      public:
          Counter(QObject* parent = nullptr) : QObject(parent) {}
          int value() const { return m_value; }
      
      public slots:
          void setValue(int value);
      
      signals:
          void valueChanged(int newValue);
      
      private:
          int m_value = 0;
      };
      #endif
      

       

      Suggestion
      Document that users should either:

      • Avoid marking Q_PROPERTY setters as slots, OR
      • Use the `-m` option on qdbuscpp2xml to avoid exposing setValue() as a standalone Method

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes