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

qdbuscpp2xml/qdbusxml2cpp: Avoid producing code that won't compile

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • D-Bus

    Description

      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);
          int value() const { return m_value; }
      
      public slots:
          void setValue(int value);
      
      signals:
          void valueChanged(int newValue);
      
      private:
          int m_value = 0;
      };
      #endif
      

       

      Steps to reproduce
      From the console, navigate to the folder that contains counter.h and run the following commands:

      qdbuscpp2xml -A counter.h -o counter.xml
      qdbusxml2cpp -m -a counteradaptor -i counter.h -l Counter counter.xml
      

       

      Outcomes
      The tools silently generate broken code. setValue() is defined twice:

      class CounterAdaptor: public QDBusAbstractAdaptor
      {
          Q_OBJECT
          Q_CLASSINFO("D-Bus Interface", "local.Counter")
          // ...
      
      public: // PROPERTIES
          Q_PROPERTY(int value READ value WRITE setValue)
          int value() const;
          void setValue(int value);
      
      public Q_SLOTS: // METHODS
          void setValue(int value);
      Q_SIGNALS: // SIGNALS
          void valueChanged(int newValue);
      };
      

       

      Suggestion
      Let the qdbus* tools detect such clashes and warn accordingly.

      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:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes