Change only a specific Default Parameter on a function
When you pass a value for a particular parameter that has a default argument, you have to pass values for all the default parameters before it. Otherwise, the value you have passed will be taken as the value for the first default parameter.
So you have to do this:
newAddress = QInputDialog::getText(
0,
"Enter an Address to Validate",
"Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
QLineEdit::Normal,
QString(),
&ok);
You can leave out passing values for the parameters after bool *
parameter.
The C++ standard states in [dcl.fct.default]/1
Default arguments will be used in calls where trailing arguments are missing.
the error is beacuse of the optional paramteres:
QString QInputDialog::getText(
QWidget * parent,
const QString & title,
const QString & label,
QLineEdit::EchoMode mode = QLineEdit::Normal,
const QString& text = QString(),
bool * ok = 0,
Qt::WindowFlags flags = 0,
Qt::InputMethodHints inputMethodHints = Qt::ImhNone)
QInputDialog::getText(
0,
"Enter an Address to Validate",
"Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)",
--> QLineEdit::EchoMode ??
--> QString& text ??
&ok);
if you set one optional parameter, you have to set all the optional paramteters to the left of that, in your case QLineEdit::EchoMode and QString& text
In C++ you can only use (one or multiple) default parameters at the end of the parameter list. If you omit parameters in the middle, the compiler has no way of knowing, which argument belongs to which parameter. Therefore you have to specify the default parameters QLineEdit::Normal and QString()
manually before passing &ok
.
In your not working case the compiler tries to match your bool pointer to the next type in the parameter list, which is QLineEdit::EchoMode
and therefore not compatible.