Use QSet
and subtract()
and count()
or size()
QStringList mOldList, mNewList;
mOldList.append("1");
mOldList.append("2");
mOldList.append("3");
mOldList.append("4");
mOldList.append("5");
mOldList.append("10");
mNewList.append("1");
mNewList.append("2");
mNewList.append("3");
mNewList.append("4");
mNewList.append("5");
mNewList.append("15");
QSet<QString> subtraction = mNewList.toSet().subtract(mOldList.toSet());
QSet<QString> subtraction1 = mOldList.toSet().subtract(mNewList.toSet());
foreach (const QString &filename, subtraction)
qDebug() << " difference: "<< filename;
foreach (const QString &filename, subtraction1)
qDebug() << " difference: "<< filename;
Result:
difference: "15"
difference: "10"
For example with next lists:
mOldList.append("1");
mOldList.append("2");
mOldList.append("3");
mOldList.append("4");
mOldList.append("5");
mOldList.append("10");
mNewList.append("1");
mNewList.append("2");
mNewList.append("3");
mNewList.append("4");
mNewList.append("5");
mNewList.append("15");
QSet<QString> subtraction = mNewList.toSet().subtract(mOldList.toSet());
foreach (const QString &fileName, subtraction)
qDebug() << " difference: "<< fileName;
Result only 15:
difference: "15"
It means that one element is not same.
mOldList.append("1");
mOldList.append("2");
mOldList.append("3");
mOldList.append("4");
mOldList.append("5");
mOldList.append("10");
mNewList.append("1");
mNewList.append("2");
mNewList.append("3");
mNewList.append("4");
mNewList.append("115");
mNewList.append("15");
Two elements are not same:
difference: "115"
difference: "15"
Or another way:
qSort(mNewList);
qSort(mOldList);
if(mNewList == mOldList){
qDebug() << "same";
}
else{
qDebug() << "not same";
}