user3443063
user3443063

Reputation: 1625

QList default parameter error message (default argument for QList<QVariant> has type int)

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

Answers (3)

Smouch
Smouch

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

Hatted Rooster
Hatted Rooster

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

The Quantum Physicist
The Quantum Physicist

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

Related Questions