Reputation: 1625
I have the following method ( which has just 1 parameter) that I want to adapt to use for more than 1 parameters. I tried to use default parameters but this doesn't work. ( The original code with just the old method works fine) What strikes me is that the variable name omitted in that daclaration. Why ?
This is my original method:
void importFile(QString *);
That is my new method:
void importFile(QString *, QList<QVariant> IMPORT_FILE_PARAMETERS =0 );
When I compile this code Qt tells me " default argument for QList IMPORT_FILE_PARAMETERS has type int
What is the problem? I don´t use int - Why would he tell me about int?
Thanks for your help
Upvotes: 1
Views: 1971
Reputation: 161
QList is not an int You are trying to assign a value 0 (zero) which is an int to that type.
Upvotes: 1
Reputation: 36503
QList<QVariant> IMPORT_FILE_PARAMETERS =0
This makes no sense. You give 0
(which is an int
, as in your error message) as a default parameter for a QList
, try to make it a default constructed list instead :
QList<QVariant> IMPORT_FILE_PARAMETERS = QList<QVariant>()
As for
What strikes me ist that the variable name omitted in that daclaration. Why ?
The compiler doesn't care about the name at all in the declaration, it only needs to know the parameter types. You can omit it in the definition of the function too but then you can't access the parameter.
Upvotes: 5
Reputation: 26346
Your default parameter is "0", which is an integer, right?
Use this:
void importFile(QString *, QList<QVariant> IMPORT_FILE_PARAMETERS = QList<QVariant>());
This will make the default parameter an empty QList
.
Upvotes: 2