Are the vectors particularly large? If not, the QMap approach described in the qSort docs might be suitable. Use vect1[i] as the key and vect2[i] as the value. The you get the vectors back using keys() and values():
QVector<double> v1;
QVector<int> v2;
v1 << 30 << 5.9 << 3.14 << 20.5 << 3.14;
v2 << 0 << 1 << 2 << 3 << 9;
QMap<double, int> sortMap;
for (int i = 0; i < v1.size(); ++i)
sortMap.insertMulti(v1.at(i), v2.at(i));
v1 = sortMap.keys().toVector();
v2 = sortMap.values().toVector();
qDebug() << v1;
qDebug() << v2;
QVector<double> v1;
QVector<int> v2;
v1 << 30 << 5.9 << 3.14 << 20.5 << 3.14;
v2 << 0 << 1 << 2 << 3 << 9;
QMap<double, int> sortMap;
for (int i = 0; i < v1.size(); ++i)
sortMap.insertMulti(v1.at(i), v2.at(i));
v1 = sortMap.keys().toVector();
v2 = sortMap.values().toVector();
qDebug() << v1;
qDebug() << v2;
To copy to clipboard, switch view to plain text mode
You need to use insertMulti() to preserve duplicates.
Bookmarks