gpt4 book ai didi

c++ - Q_DECLARE_METATYPE 期望 ctor、dtor 或之前的类型转换; token

转载 作者:行者123 更新时间:2023-11-27 23:47:06 25 4
gpt4 key购买 nike

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

enter image description here

值范围.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

最佳答案

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

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

#include <QMetaType>

关于c++ - Q_DECLARE_METATYPE 期望 ctor、dtor 或之前的类型转换; token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49706518/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com