Re: Return value to QList
think on an impossible value and add it to the list. If the list has only that value, it's like empty.
Re: Return value to QList
What about a "bool* ok" function argument?
Re: Return value to QList
IF you want to test for NULL then you might try returning a QList<int> *.
jw
sw developer
Re: Return value to QList
Quote:
think on an impossible value and add it to the list. If the list has only that value, it's like empty.
that's what I thought when I said about returning the first element set as -1... but, that's so... not elegant. :p
Quote:
What about a "bool* ok" function argument?
I can't change any arguments, but maybe I can use that sugestion somewhere else. thanks
Quote:
IF you want to test for NULL then you might try returning a QList<int> *.
if you meant
Code:
return QList<int> *;
that doesn't work. I've got nooo idea why.
thank you all, I think I'll have to rely in 'not elegant' methods XD
Re: Return value to QList
The "bool *ok" solution is the best. If you can't alter the arguments but you can alter the returned value you can use
Code:
QPair<bool, QList<int> > returnListFunction() {}
Re: Return value to QList
Quote:
Originally Posted by
lyucs
What can I return instead?
You can return an empty list and besides that have a "lastError" method in your class to determine if the last call was successful or not. Qt uses this approach in many places as an alternative to exceptions.
Re: Return value to QList
I use a public bool variable in the class, than, set it in the beginning of the method and change it if the error occur. After calling the method, I check the flag value.