Important: Please read the Qt Code of Conduct -

What is the time complexity of QVector::toList() method?

  • Does QVector()::toList() produce a new QList in O(n) by iterating and copying elements, or is this perhaps an O(1) operation? My testing indicates that this is a linear time conversion. Am I correct?

    In general, is there documentation available regarding complexities for other related conversion operations, like fromList(), toStdVector() etc.?

  • QVector()::toList(), QList::toVector and the fromList/Vector() methods are all copy element by element of one to the other. It's trivial to check:

    QVector::toStdVector can leverage the fact that they both use contiguous memory and it boils down to little more than a memcpy

    Some methods/classes declare their complexity in the description but I would say it's the exception rather than the norm

Log in to reply