How to find object in QList by specific field in c++98?

Viewed 15933

I have this simple class:

class SomeClass
{
   QString key;
   QString someData;
   int otherField;
   public:
      QString getKey() { return key };
};

And I have this list:

QList<SomeClass*> myList;

I want to check if myList contains object with key = "mykey1";

for(int i = 0; i < myList.size(); i++)
{
  if(myList.at(i)->getKey() == "mykey1") 
  { 
      //do something with object, that has index = i
  }
}

Is there any standard function, that will do cycle and return this object or index or pointer ? , so I don't need to use cycle

2 Answers
Related