PDA

View Full Version : &arg1



collycrk
20th August 2015, 14:08
void test_Dialog::on_SaveUpdateComboBox_activated(const QString &arg1)
{
QString myarg;
myarg = ui->SaveUpdateComboBox->currentText();

if (myarg == "Update Work Order"){
ui->label_status->setText("Updating the Work Order table.....");
}
I am going to use a combobox to save/update to different database tables.
I'm getting a warning that tells me the arg1 option in the above test_Dialog line above is not being used.
(unused parameter arg1) is the warning.

My question is how do I use these parameters? I have tried myarg = &arg1; but that gives an error.

Thanks for your time and help on this matter, it will be appreciated! :-)

Please excuse the red-lipped smiley face in the text, if you do not see one I'm not seeing thing it was in the preview of this post.

anda_skoa
20th August 2015, 14:21
My question is how do I use these parameters? I have tried myarg = &arg1; but that gives an error.

myarg is of type "QString", the expression on the right hand side of the = is of type "QString*" (pointer to QString) due to using the & operator to get the address of "arg1".
There is no automatic conversion from "QString*" to "QString" so the compiler cannot accept this assignment.

You have several options:

1) remove the argument
2) remove the argument name
3) use Q_UNUSED(arg1) to slience the warning
4) use the argument instead of a local variable
5) use the argument (not its address) to initialize the local variable instead of getting the value from the combo box.

Cheers,
_

collycrk
20th August 2015, 14:28
Thanks anda_skoa. :-)
Your answers 4 and 5 I do not know how to do. Would you give me a code sample?
Also any advise concerning the 'Qt best practice' way of doing this would help as well.

anda_skoa
20th August 2015, 16:06
Your answers 4 and 5 I do not know how to do. Would you give me a code sample?

for (4)


if (arg1 == "Update Work Order"){

for (5)


QString myarg = arg1;




Also any advise concerning the 'Qt best practice' way of doing this would help as well.

My first suggestion would be to not rely on the text displayed in the combo box but the index.
The index is numerical and will be the same for the respective entry, while the text is likely subjcet to translation.

Another suggestion is to not use the "connect by name" feature, which I guess you currently do (the slot name suggests that).
Explicit connect() is way more robust against changes in the designer part of the application.

Cheers,
_

collycrk
3rd September 2015, 17:43
Update to this thread.
Thanks again for your instructions.
The coding is coming along well with your help.

Thanks again.
This thread is solved!!