Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
6.8.1
-
None
-
Qt 6.8.1,Qt Creator 15.0.0, C++17
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)
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 = {`