October 10, 2011

pratik041 pratik041
Lab Rat
346 posts

How can i call a function with three arguments while a button is clicked?

 

I have a function with three arguments

  1. void Button::set_image (QPixmap &new_image,
  2.                         int     num_states,
  3.                         QRect   &rect)

I want to call it when a button is clicked. My problem is that if i will use “QObject::connect();” then i can’t pass arguments so how can i do it?

 Signature 

Pratik Agrawal

7 replies

October 10, 2011

Lukas Geyer Lukas Geyer
Lab Rat
2074 posts

Just create a slot which is connected to the clicked() signal and calls your set_image() method.

October 10, 2011

pratik041 pratik041
Lab Rat
346 posts

but in this case how i will pass arguments to the set_image function from outside the class?

 Signature 

Pratik Agrawal

October 10, 2011

fluca1978 fluca1978
Lab Rat
529 posts

You need to store your internal status somewhere, maybe in the class, or in another class or in ad-hoc structure, and then retrieve it from within your slot, and pass it to the final method.

October 10, 2011

pratik041 pratik041
Lab Rat
346 posts

Their is not any other method where we can call function directly and pass the arguments.

 Signature 

Pratik Agrawal

October 10, 2011

fluca1978 fluca1978
Lab Rat
529 posts

Not using signals and slots. In this case you have to manually compute your status using a slot and, maybe, emitting a new signal.

October 10, 2011

Andre Andre
Robot Herder
6419 posts

Note that it is perfectly possible to have signals and slots with multiple arguments. So I don’t really understand the issue.

If you want to connect to a slot with three arguments, you just make sure you have a signal that matches that. I guess what you want to do, is connect a signal with no parameters to a slot that has multiple, while supplying the values for the arguments at connect time. Right? There is no direct support for that. However, you can do it indirectly. You can take some inspiration from QSignalMapper, and create a version of that supporting multiple arguments. Or, you wait for Qt5 and use a lambda function.

October 11, 2011

pratik041 pratik041
Lab Rat
346 posts

ok i will try………….

 Signature 

Pratik Agrawal

 
  ‹‹ Set delegate for one cell(item)      Creating Dynamic Properties in a custom widget that shows in Qt Designer ››

You must log in to post a reply. Not a member yet? Register here!