Is there any way for a QStringList (or any list) to have a default value in a function or class declaration?
Is there any way for a QStringList (or any list) to have a default value in a function or class declaration?
Yes, why not. Just create another QStringList (or any list) and initialise the your QStringList with it.
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
Thank you Santosh
I have not explained myself well. I want a DEFAULT value for a variable in a an arguments list. An example follows:
Qt Code:To copy to clipboard, switch view to plain text mode
Obviously this does not compile because the lblTexts is a list NOT a QString. lblTexts = {} does nor work either.
Is there a way of declaring a default for a QStringList in a case like this?
Thank you again for you help.
Regards
G
and You have an empty list as the default value.Qt Code:
MyinputDlg(QString title = "My Input Dialogue", QStringList lblTexts = QStringList(), QString def = "");To copy to clipboard, switch view to plain text mode
QStringList and QString variables are always defaulted to an empty QStringList (same as assigning it to QStringList(), as Lesiok explains), and QString defaults to an empty string. So these two are exactly the same in their effect:Is there a way of declaring a default for a QStringList in a case like this?
Qt Code:
MyinputDlg(QString title = "My Input Dialogue", QStringList lblTexts = QStringList(), QString def = ""); // and To copy to clipboard, switch view to plain text mode
The only time you need the first form is if the variable(s) with the default value(s) are not at the end of the list of variables:
Qt Code:
MyinputDlg(QString title = "My Input Dialogue", QStringList lblTexts = QStringList(), QString def = "Something non-default");To copy to clipboard, switch view to plain text mode
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
GrahamB (13th May 2017)
Bookmarks