Important: Please read the Qt Code of Conduct -

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

  • I have a function with three arguments
    @void Button::set_image (QPixmap &new_image,
    int num_states,
    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?

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

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

  • 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.

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

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

  • 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.

  • ok i will try.............

Log in to reply