我在赋值运算符中使用了SIGSEGV,正是在重写枚举时 我的结构:
struct Pawn
{
private:
Q_GADGET
public:
Q_PROPERTY(Position position MEMBER m_position)
Q_PROPERTY(PawnType pawnType MEMBER m_pawnType)
Pawn() : m_position(Position::NotDefined), m_pawnType(PawnType::None) {}
Pawn(const Pawn &a_other)
{
this->m_pawnType = a_other.m_pawnType;
this->m_position = a_other.m_position;
}
Pawn &operator=(const Pawn &a_other)
{
this->m_pawnType = a_other.m_pawnType;
this->m_position = a_other.m_position;
return *this;
}
~Pawn(){}
enum Position
{
NotDefined = 0,
Bottom,
Left,
Top,
Right
};
enum PawnType
{
None = 0,
Circle,
Square,
Diamond,
Triangle,
};
Q_ENUMS(Position)
Q_ENUMS(PawnType)
Position m_position;
PawnType m_pawnType;
};
typedef Pawn::PawnType PawnType;
typedef Pawn::Position Position;
Q_DECLARE_METATYPE(Pawn)
Q_DECLARE_METATYPE(Pawn::Position)
Q_DECLARE_METATYPE(Pawn::PawnType)
导致错误的行:
m_board[a_pawnPosition.y()][a_pawnPosition.x()] = m_board[current.y()][current.x()];
m_board[current.y()][current.x()] = Pawn();
m_board
的定义:
Pawn m_board[10][10];
a_pawnPosition
和current
在界限
它并不总是发生。我想Q_PROPERTY可能会导致它,但我需要它们从QML中读取值并且不知道如何解决它。
答案 0 :(得分:0)
你是对的。 current
超出范围,因为它是引用,而不是复制值,有时我会在QList
前几行删除它。谢谢你的回答。