Results 1 to 4 of 4

Thread: Working with Slots

  1. #1
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Smile Working with Slots

    hi all
    suppose that i have two QPushButton that named A , B .
    i want connect clicked signal of button A,B to a slot that take a parameter(int id).
    for example: when i clicked button A, my slot be called with '1' for id parameter and about button B with '2'.
    i do not know how to implement this.
    i used the following code but gives me some errors.
    Qt Code:
    1. /* in my class */
    2. private slots:
    3. void myslot(int id);
    4.  
    5. // *********************
    6. /* for use this slot i use the below code */
    7. connect(btn_A , SIGNAL(clicked()) , this , SLOT(myslot(1));
    8. connect(btn_B , SIGNAL(clicked()) , this , SLOT(myslot(2));
    To copy to clipboard, switch view to plain text mode 
    Life is about making the right decisions and moving on.

  2. #2
    Join Date
    Jan 2012
    Location
    Iran, Tehran
    Posts
    308
    Thanks
    75
    Thanked 24 Times in 21 Posts
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Working with Slots

    salam!
    you can't do this. the order of signal parameters have to be same as slot parameters. in other words u can't have a slot that takes one argument and connect it to a signal without any args.

    In addition your implementation of signal and slot is incorrect. it's better to have a study about this. In the slot's argument you have to put type of argument not its value! the value is sent by signal

  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Working with Slots

    As alizadeh91 already said you should learn the basics about signals and slots from documentation, see this link.

    And for your problem a solution might be to use QSignalMapper //but if you only have two buttons you might want to create separate slots connected to click signal and from within those slots call myslot with the corresponding parameter.

  4. #4
    Join Date
    Jun 2012
    Location
    Iran , Tehran
    Posts
    93
    Thanks
    5
    Platforms
    Unix/X11 Windows Android

    Default Re: Working with Slots

    thanks a lot a lot ... Mr Zlatomir
    my problem solved by using QSignalMapper
    thanks again...
    Life is about making the right decisions and moving on.

Similar Threads

  1. Replies: 7
    Last Post: 24th September 2012, 07:17
  2. Why so few slots?
    By hakermania in forum Newbie
    Replies: 3
    Last Post: 8th April 2011, 16:32
  3. How do you add slots?
    By rakkar in forum Newbie
    Replies: 10
    Last Post: 26th August 2009, 23:11
  4. Slots or new slots
    By Colx007 in forum Qt Programming
    Replies: 3
    Last Post: 21st January 2008, 17:38
  5. Signals/Slots stopped working
    By Jimmy2775 in forum Qt Programming
    Replies: 8
    Last Post: 31st March 2006, 21:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.