我在这里看到过其他问题,但它们处理指针或与qobject派生类,所以它们似乎不相关。qlist自定义类无法追加
我试图值追加到自定义类的QList,使用这里是类
class matchPair
{
public:
matchPair(int a=0, int b=0)
: m_a(a)
, m_b(b)
{}
int a() const { return m_a; }
int b() const { return m_b; }
bool operator<(const matchPair &rhs) const { return m_a < rhs.a(); }
// matchPair& operator=(const matchPair& other) const;
private:
int m_a;
int m_b;
};
class videodup
{
public:
videodup(QString vid = "", int m_a = 0, int m_b = 0);
~videodup() {}
QString video;
bool operator==(const QString &str) const { return video == str; }
// videodup& operator=(QString vid, int m_a, int m_b);
QList<matchPair> matches;
};
struct frm
{
QString file;
int position;
cv::Mat descriptors;
QList<videodup> videomatches;
};
QList<frm> frames;
和失败的路线是:
frame.videomatches.at(frame.videomatches.indexOf(vid)).matches.append(pair);
我得到的错误是:
/usr/local/Cellar/qt5/5.5.1_2/lib/QtCore.framework/Headers/qlist.h:191: candidate function not viable: 'this' argument has type 'const QList<matchPair>', but method is not marked const
void append(const T &t);
^
我做错了什么?
现在你还没有指定'frame'的类型以及它是如何被创建的。有一个'const'的地方,这是肯定的。 – iksemyonov
对于未来的读者,我上面的评论是错误的,诀窍在'QList :: at()'方法中。所提供的信息足以解决问题。 –
iksemyonov