[英]Convert QList iterator to index
I use qLowerBound to find an item in a QList
, but this function returns an iterator, while I need an index (I'll pass it to another function that expects an index).我使用qLowerBound在
QList
查找一个项目,但是这个函数返回一个迭代器,而我需要一个索引(我会将它传递给另一个需要索引的函数)。 Is there a way to get the index from the QList
iterator?有没有办法从
QList
迭代器中获取索引?
You can subtract iterator to beginning of your list from your iterator to get an index, since pointer arithmetic is defined on iterators:您可以从迭代器中减去到列表开头的迭代器以获得索引,因为指针算法是在迭代器上定义的:
int idx = iter-yourList.begin();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.