Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can i call a function with three arguments while a button is clicked?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

    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?

    Pratik Agrawal

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pratik041
        wrote on last edited by
        #3

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

        Pratik Agrawal

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pratik041
            wrote on last edited by
            #5

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

            Pratik Agrawal

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fluca1978
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pratik041
                  wrote on last edited by
                  #8

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

                  Pratik Agrawal

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved