Q_DECLARE_METATYPE之前需要ctor,dtor或类型转换;代币

时间:2018-04-07 10:43:07

标签: c++ qt

该类工作正常,但现在我需要将它存储在QVariant中。以为我只需像往常一样添加Q_DECLARE_METATYPE(Docs),但不会在添加宏的情况下编译。

enter image description here

ValueRange.h

#ifndef VALUERANGE_H
#define VALUERANGE_H

template <typename T>
class ValueRange{
public:
    ValueRange() = default;
    ValueRange(const ValueRange &other) 
        : isInverted_(other.isInverted_), min_(other.min_), max_(other.max_){}
    ~ValueRange() = default;
    ValueRange(const T &min, const T &max) : min_(min), max_(max){}

    T min() const{ return min_; }
    T max() const{ return max_; }
    void invert(){ isInverted_ = true; }
    bool isInverted() const{ return isInverted_; }

    bool operator==(const ValueRange &other) const{
        return other.min()==min_ && other.max()==max_;
    }
    bool operator!=(const ValueRange &other) const{
        return other.min()!=min_ || other.max()!=max_;
    }
private:
    bool isInverted_ = false;
    T min_;
    T max_;
};
using IntRange = ValueRange<int>;
using DoubleRange = ValueRange<double>;
Q_DECLARE_METATYPE(IntRange);
Q_DECLARE_METATYPE(DoubleRange);

#endif // VALUERANGE_H

1 个答案:

答案 0 :(得分:3)

您只阅读如何开始指南。尝试阅读从如何开始引用的手册QMetaType Class

特别是您忘记添加必需的include。

#include <QMetaType>
相关问题