Search code examples
qtcountqlist

qlist.count by a condition in qt


I have a Qlist of myStruct like QList<myStruct> list.

myStruct contains a bool parameter (active). i.e. I have list[i].active.

I want to count number of list elements that active parameter is equivalent to true.

I use qCount. But it needs a value to compare, not a condition.

what can I do? Thanks.


Solution

  • If you not want use simple loop as suggested before. You can support your own counter that will make appropriate increment\decrement when add\remove elements.