Change only a specific Default Parameter on a function
Clash Royale CLAN TAG#URR8PPP
I'm using qt
and I am trying to use the QInputDialog::getText()
function to get input from the user, from the Documentation the definition of the function is:
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)
and here is my code:
bool ok=0;
newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
"Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
,&ok);
but I get the Error:
error: no matching function for call to 'QInputDialog::getText(int, const char [29], const char [80], bool*)'
,&ok);
^
but when I pass in all the arguments before the *ok
argument like:
bool ok=0;
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);
it works.
I really don't understand why cant I just change the default parameter I want and leave the rest as default?.
c++ qt qt5
add a comment |
I'm using qt
and I am trying to use the QInputDialog::getText()
function to get input from the user, from the Documentation the definition of the function is:
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)
and here is my code:
bool ok=0;
newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
"Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
,&ok);
but I get the Error:
error: no matching function for call to 'QInputDialog::getText(int, const char [29], const char [80], bool*)'
,&ok);
^
but when I pass in all the arguments before the *ok
argument like:
bool ok=0;
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);
it works.
I really don't understand why cant I just change the default parameter I want and leave the rest as default?.
c++ qt qt5
add a comment |
I'm using qt
and I am trying to use the QInputDialog::getText()
function to get input from the user, from the Documentation the definition of the function is:
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)
and here is my code:
bool ok=0;
newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
"Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
,&ok);
but I get the Error:
error: no matching function for call to 'QInputDialog::getText(int, const char [29], const char [80], bool*)'
,&ok);
^
but when I pass in all the arguments before the *ok
argument like:
bool ok=0;
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);
it works.
I really don't understand why cant I just change the default parameter I want and leave the rest as default?.
c++ qt qt5
I'm using qt
and I am trying to use the QInputDialog::getText()
function to get input from the user, from the Documentation the definition of the function is:
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)
and here is my code:
bool ok=0;
newAddress = QInputDialog::getText(0,"Enter an Address to Validate",
"Adress: comma separated (e.g Address line 1, Address line 2, City, Postal Code)"
,&ok);
but I get the Error:
error: no matching function for call to 'QInputDialog::getText(int, const char [29], const char [80], bool*)'
,&ok);
^
but when I pass in all the arguments before the *ok
argument like:
bool ok=0;
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);
it works.
I really don't understand why cant I just change the default parameter I want and leave the rest as default?.
c++ qt qt5
c++ qt qt5
edited Mar 6 at 16:03
Makhele Sabata
asked Mar 6 at 9:52
Makhele SabataMakhele Sabata
10917
10917
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
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.
I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.
– Makhele Sabata
Mar 6 at 13:15
You are welcome.
– P.W
Mar 6 at 13:33
add a comment |
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.
add a comment |
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
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55020088%2fchange-only-a-specific-default-parameter-on-a-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.
– Makhele Sabata
Mar 6 at 13:15
You are welcome.
– P.W
Mar 6 at 13:33
add a comment |
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.
I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.
– Makhele Sabata
Mar 6 at 13:15
You are welcome.
– P.W
Mar 6 at 13:33
add a comment |
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.
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.
edited Mar 6 at 11:55
answered Mar 6 at 10:11
P.WP.W
18k41657
18k41657
I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.
– Makhele Sabata
Mar 6 at 13:15
You are welcome.
– P.W
Mar 6 at 13:33
add a comment |
I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.
– Makhele Sabata
Mar 6 at 13:15
You are welcome.
– P.W
Mar 6 at 13:33
I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.
– Makhele Sabata
Mar 6 at 13:15
I worked with Python when i started learning programming, and it i had this functionality where you could pass the arguments by name. it would be nice if they had something like that in C++. Thanks for the answer I wasn't aware of the trailing arguments issue.
– Makhele Sabata
Mar 6 at 13:15
You are welcome.
– P.W
Mar 6 at 13:33
You are welcome.
– P.W
Mar 6 at 13:33
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 6 at 10:08
AlbertMAlbertM
524418
524418
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Mar 6 at 10:24
ΦXocę 웃 Пepeúpa ツΦXocę 웃 Пepeúpa ツ
34.1k113965
34.1k113965
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55020088%2fchange-only-a-specific-default-parameter-on-a-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown