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

QBindableInterface iface 声明为 constexpr 导致 QBindable 构造错误

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.8.1
    • Core: Other
    • None
    • Qt 6.8.1,Qt Creator 15.0.0, C++17
    • Windows

    Description

      引发错误的代码:

      ```

      #include <QObject>
      #include <QBindable>
      #include <QProperty>
      #include <QDebug>

      class Foo : public QObject
      {
          Q_OBJECT
          Q_PROPERTY(int myVal READ myVal WRITE setMyVal NOTIFY myValChanged CONSTANT)
      public:
          explicit Foo():m_myVal(5){}
          int myVal() const { return m_myVal; }
          void setMyVal(int newvalue)

      {         if(m_myVal == newvalue) return;         m_myVal = newvalue;         emit myValChanged(newvalue);     }

      signals:
          void myValChanged(int newVal);

      private:
          int m_myVal;
      };

      int main()

      {     Foo myfoo;     QBindable<int> obj(&myfoo, "myVal");     QProperty<int> prop([&]()\{return obj.value();}

      );
          auto change = prop.onValueChanged([&](){qDebug() << "value changed:" << prop.value();});
          myfoo.setMyVal(10); 

          return 0;
      }

      #include "main.moc"

      ```

      编译上述代码时出现如下错误:

       error: constexpr variable 'iface<int>' must be initialized by a constant expression

       

      解决办法:修改 qproperty.h 文件  667 行 代码 `inline constexpr QBindableInterface iface = {`为`inline QBindableInterface iface = {`

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            lishiying sy l
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes