Я создал следующий класс:не может реализовать оператор ==(), чтобы сравнить объект пользовательского класса к QString
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; }
bool operator==(const videodup &dup) const {return video == dup.video;}
QList<matchPair> matches;
};
videodup::videodup(QString vid = "", int m_a = 0, int m_b = 0)
{
video = vid;
matches.append(matchPair(m_a, m_b));
}
Я думал, что это позволит мне использовать в QList::contains()
QString
, но он дает мне ошибка:
/usr/local/Cellar/qt5/5.5.1_2/lib/QtCore.framework/Headers/qlist.h:981: error: invalid operands to binary expression ('videodup' and 'const videodup')
if (i->t() == t)
~~~~~~^~
/Users/phire/Documents/workspace/VideoTwin/matchpair.h:30: candidate function not viable: no known conversion from 'const videodup' to 'QString &' for 1st argument
bool operator==(QString &str) { return video == str; }
^
нарушитель линия:
if (frame.videomatches.contains(vid))
ч прежде чем это код объясняя строку выше
struct frm
{
QString file;
int position;
cv::Mat descriptors;
QList<videodup> videomatches;
};
QList<frm> frames;
void MainWindow::findDupes(frm &frame)
{
QString file = frame.file;
UMat mat = frame.descriptors.getUMat(cv::ACCESS_RW);
UMat indices;
UMat dists;
if (!mat.isContinuous() || mat.empty())
return;
QTime timestamp(0,0,0,0);
timestamp = timestamp.addMSecs(frame.position);
try
{
mat = mat.reshape(1,1);
index.knnSearch(mat,indices,dists,5);
}
catch (Exception e)
{
qWarning() << "index search failure" << e.err.c_str() << e.msg.c_str();
}
catch (exception& e)
{
qWarning() << "index search failure" << e.what();
}
// qDebug() << "indices cols" << indices.cols << "dists cols" << dists.cols;
db.transaction();
QSqlQuery matches(db);
QStringList tempmatches;
Mat indicesMat = indices.getMat(cv::ACCESS_READ);
Mat distsMat = dists.getMat(cv::ACCESS_READ);
for (int i = 0; i < indicesMat.cols; i++)
{
if (indicesMat.at<int>(0,i) == -1 || distsMat.at<int>(0,i) > 12800)
continue;
try
{
QTime matchtime(0,0,0,0);
int matchms = frames.at(indicesMat.at<int>(0,i)).position;
QString vid = frames.at(indicesMat.at<int>(0,i)).file;
matchtime = matchtime.addMSecs(matchms);
int temp = distsMat.at<int>(0,i);
tempmatches.append(QString::number(indicesMat.at<int>(0,i)));
if (frame.videomatches.contains(vid))
{
matchPair pair(frame.position, indicesMat.at<int>(0,i));
frame.videomatches[ frame.videomatches.indexOf(vid) ].matches.append(pair);
}
else
{
frame.videomatches.append(videodup(vid,frame.position, indicesMat.at<int>(0,i)));
}
// qDebug() << frame.file << "frame"<< timestamp.toString("hh:mm:ss") << "match at"<< vid << matchtime.toString("hh:mm:ss") << "distance" << temp;
}
catch (Exception e)
{
qWarning() << "failure in indices" << e.err.c_str() << e.msg.c_str() << e.func.c_str();
}
catch (exception &e)
{
qWarning() << "failure in indices" << e.what();
}
}
QString temp(tempmatches.join(","));
matches.prepare("UPDATE frames SET matches = :matches WHERE file = :file AND position = :position");
matches.bindValue(":matches",temp);
matches.bindValue(":file",frame.file);
matches.bindValue(":position",frame.position);
if (!matches.exec())
qWarning() << "couldn't add matches to frame in database";
db.commit();
}
Как я могу сделать мой собственный класс сопоставим с QString
?
Neal - это тот же код, или он изменился с тех пор? Вы, к сожалению, удалили пасту, опять же я забыл (и это неясно, в первую очередь), что такое 'frame',' frame.videomatches' и 'vid'. Это важно. – iksemyonov
пытался только вставить соответствующие биты http://pastebin.com/8WP8jT5P – Neal
Хорошо, я вижу вашу проблему, думая, как обойти ее. С STL это было бы легко возможно, с Qt мне нужно немного подумать. – iksemyonov