c++ - Qt 5.7.1/GCC 6.3.0:错误:constexpr函数的主体'静态constexpr int QMetaTypeId2 <T>

标签 c++ qt c++11 qt5 debian-stretch

这段代码

namespace Config {
  class Value {
  public:
    enum Type {
      Null,
      Integer,
      String,
      Map,
      List,
      Boolean
    };

    Value();
    Value(int v);
    Value(const QString &v);
    Value(const QMap<QString, Value> &v);
    Value(const QList<Value> &v);
    Value(bool v);

    template<class T> T get() const {
      return value.value<T>();
    }

    enum Type type() const;
    enum Type listType() const;
    bool isNull() const;

    void setListType(enum Type t);

    operator QString() const;
    QString toString() const;

  private:
    QVariant value;
    enum Type value_type;
    enum Type list_elements_type;
  };
}

Q_DECLARE_METATYPE(Config::Value)
(https://github.com/olegantonyan/mpz/blob/master/app/config/value.h)
在最新版本的gcc / qt上编译,但在Debian Stretch(gcc 6.3.0,qt 5.7.1)上失败
../../../../include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:746:47: error: static assertion failed: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system

../../../../include/x86_64-linux-gnu/qt5/QtCore/qmetatype.h:1604:100: error: body of constexpr function 'static constexpr int QMetaTypeId2<T>::qt_metatype_id() [with T = std::nullptr_t]' not a return-statement
完整日志https://build.opensuse.org/package/live_build_log/home:oleg_antonyan/mpz/Debian_9.0/x86_64
在CentOS7(gcc 4.8.5,qt 5.6.1)上也可以正常工作。尚未在较旧的版本上进行测试。
有什么想法可能是错的吗?

最佳答案

发现问题:
构造函数中的value.setValue(nullptr);,其中值是QVariant。
删除了这一行,现在可以编译了。不知道为什么我要放在第一位

关于c++ - Qt 5.7.1/GCC 6.3.0:错误:constexpr函数的主体'静态constexpr int QMetaTypeId2 <T>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63527747/

相关文章:

c++ - 数组指针数组的析构函数

qt - 将 Qxt 插件添加到 Designer

c++ - mongocxx 游标和右值引用

c++ - std::for_each 优于 for 循环的优点

c++ - 两个连续的换行符作为分隔符 - C/C++

c++ - QObject :connect No such slot issue

c++ - 操纵 QGradient 以遵循路径

c++ - initializer_list 结合其他参数

linux - 使用 C++11(Linux;clang 3.8)时 CUDA nvcc 编译器失败

c++ - 编译 fatal error 头文件g++