Coming from a C# background, I have some habbits that need to be changed. I’m tring to return a QList<int> from a function. The compiler error message is conversion from ‘QList*’ to non-scalar type ‘QList’ requested. Here is the function:
QList<int> toCategories(QVariant qv)
{
QList<int>categories = new QList<int>();
if(qv.isValid() && qv.type() == QVariant::List)
{
foreach(QVariant category,qv.toList()){
categories.append(category.toInt() );
}
}
return categories;
}
I’d appreciate a link to the documentation or a function using the correct syntax
The error is referring to the fact that you are attempting to covert between a non-pointer
QListto a pointer to aQList. You need to either use a pointer to aQListas follows:Alternately, you can use a non-pointer
QList:Since you are new to C++, I would recommend reviewing this question.
If I may also point out, your function as listed has a problem where a certain path doesn’t return a value (though I suspect that might be because you only copy-pasted a portion of your code).