0

I have a function which is declared as:

bool getIndex(const QString itemUid, QModelIndex& index /*out*/);

how do I declare an object to pass in as index?

I have tried:

QModelIndex *modelIndex;
getIndex(auid, modelIndex  );

with and without the "*", but I get compile errors.

The compilation error is:

no matching function for call to TreeModel::getIndex(QString, QModelIndex*&)

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
Michael Vincent
  • 1,620
  • 1
  • 20
  • 46

2 Answers2

1

Compiling without the * shouldn't give you errors (assuming you are not doing something like QModelIndex *modelIndex();).

Another way to solve your problem would be to declare your function like so :

bool getIndex(const QString itemUid, QModelIndex* index /*out*/);

And then create your object as a reference like before:

QModelIndex *modelIndex;
getIndex(auid, modelIndex);

The downside to this though is that you'd have to change the function everywhere you use index to instead treat it like a pointer rather than reference. I find it more likely that your error may lie elsewhere in your code, and be the nature of the QModelIndex object.

TheSmartWon
  • 424
  • 3
  • 10
-3

The requested argument is QModelIndex&, so you can just call

QModelIndex modelIndex();
getIndex(auid, modelIndex);

Btw: QModelIndex is a really slim object which gets invalid very quickly. You should not create pointers to it without deep insight to Qt's Model/View system.

Christian
  • 114
  • 6