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 we pass arguments while implementing slots?
QtWS25 Last Chance

How can we pass arguments while implementing slots?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.0k Views
  • 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 animate_button(bool); slots. I want while i am clicking a button i want to implement slot as animate_button(false);. I want something like this
    @QObject::connect (button2, SIGNAL(clicked()), button2, SLOT(animate_button(false))); @ but it is not working. How can i do it?

    Pratik Agrawal

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      You can only use a slot with less parameters as the signal in your connect statement, so in this case none.
      @QObject::connect (button2, SIGNAL(clicked()), button2, SLOT(animate_button()));@

      In your animate_button() slot you can set a variable to false

      If you want to interact with the toggled state of a button you could use the signal "toggled":http://doc.qt.nokia.com/4.7/qabstractbutton.html#toggled

      In that case you can pass a boolean

      @QObject::connect (button2, SIGNAL(toggled(bool)), button2, SLOT(animate_button(bool)));@

      I suggest you to read about "signals and slots":http://doc.qt.nokia.com/4.7/signalsandslots.html to understand the rules that apply.

      Qt Certified Specialist
      www.edalsolutions.be

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

        If you don't want to use the checkable property of the button, your only way to achieve this is to keep the status of the animation (e.g., started = true|false) somewhere else, and each time you handle the clicked() signal you manually toggle the animation status. Another way is to provide two different slots, let say animation_start and animation_stop. In each slot you disconnect the slot itself from the signal handling and connect the other one, so each time the button is clicked one of the two slots handles the signal alternatively.

        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