我在這裏看到過其他問題,但它們處理指針或與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