Results 1 to 13 of 13

Thread: Signal and slot

  1. #1

    Default Signal and slot

    Hii

    How can I use a Slot with an argument whenever a push button is clicked

  2. #2
    Join Date
    Oct 2007
    Posts
    201
    Thanks
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Signal and slot

    Quote Originally Posted by jayreddy View Post
    Hii

    How can I use a Slot with an argument whenever a push button is clicked
    And what is the argument u r passing in Slot.? if it is bool, then u can use like

    Qt Code:
    1. connect(pushButton, SIGNAL(clicked ( bool),this, SLOT(slot(bool));
    To copy to clipboard, switch view to plain text mode 
    Cheers,
    Phillip



    --- Please post the solution you got to solve your problem. It may help others.

  3. #3

    Default Re: Signal and slot

    I want to pass a pointer of a class to the slot not bool or some other type

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal and slot

    Then you'll need to create your own SLOT and SIGNAL.

    eg.

    Qt Code:
    1. void mySignal(myClass *c);
    To copy to clipboard, switch view to plain text mode 

    and then

    Qt Code:
    1. emit mySignal(myClassPtr);
    To copy to clipboard, switch view to plain text mode 

    in your click slot.

  5. #5
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Signal and slot

    There is big chance that you want to do something strange. Please explain what you want to do and we will help you how to map that to the Qt-way.

    Anyway, if you want to get the sender object, check the sender()-function in your slot.

    But be warned again: There is only rare cases where this is a good idea and I doubt that you hit one of these.
    It's nice to be important but it's more important to be nice.

  6. #6
    Join Date
    Nov 2009
    Location
    Austria
    Posts
    30
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: Signal and slot

    hi ,

    got somehow a similar problem:

    my programm should calculate how to place packages on a stack, therefore i created a main_acting_class which actually contains all needed functions, anyway to enter values i got some dialogs and i want to close them, but i can't connect the signals.

    I'll show what i mean:

    Qt Code:
    1. connect(ui_package.pb_ok,SIGNAL(clicked()),this,SLOT(dia_package.accept()));
    To copy to clipboard, switch view to plain text mode 
    this actually won't work, i don't know why i can't use it like that. i also tried:
    Qt Code:
    1. connect(ui_package.pb_ok,SIGNAL(clicked()),dia_package,SLOT(accept()));
    To copy to clipboard, switch view to plain text mode 
    wasn't a good idea either, so i thought of creating a method which closes the dialogs for me, so i wrote this:
    Qt Code:
    1. void acting_class::close_dialog(QDialog* d){
    2. d->accept();
    3. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. connect(ui_package.pb_ok,SIGNAL(clicked()),this,SLOT(close_dialog(dia_package)));
    To copy to clipboard, switch view to plain text mode 
    but i guess d is in this case no pointer like in c#, so anyone got an idea what i could do about this little problem?

    thx
    tobi

  7. #7
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Signal and slot

    The second attempt should work and is the way it is supposed to work. Please provide more info what was not working there.

    Indeed d IS a pointer.
    It's nice to be important but it's more important to be nice.

  8. #8
    Join Date
    Nov 2009
    Location
    Austria
    Posts
    30
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal and slot

    ok,
    the error is:

    Qt Code:
    1. C:/Users/Tobias/Desktop/Schule/AINF/Diplomarbeit/New01/acting_class.cpp:20: error: no matching function for call to 'acting_class::connect(QPushButton*&, const char*, QDialog&, const char*)'
    To copy to clipboard, switch view to plain text mode 

    and i can't use autocomplete in SLOT(), little wired

  9. #9
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Signal and slot

    The receiver object has to be a pointer to a QObject. Prepend the receiver with & to take the adress of the object and converting object to pointer.
    It's nice to be important but it's more important to be nice.

  10. The following user says thank you to axeljaeger for this useful post:

    T0bi4s (8th December 2009)

  11. #10
    Join Date
    Nov 2009
    Location
    Austria
    Posts
    30
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Signal and slot

    thx mr axel jäger now it works

  12. #11

    Default Re: Signal and slot

    hii..

    Even I did the same what you did, passing a pointer of a class as an argument to the slot.
    my own class lineedit..
    lineedit *t ;

    connect (t->temp, SIGNAL(clicked()), this, SLOT(del_tag1(t)));
    (temp is pushbutton defined in that class)

    But an error saying

    Object::connect: No such slot QOlaiTagsWidget::del_tag1(t)

    is displaying.


    Can you help me regarding this .

    Thank You

  13. #12
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: Signal and slot

    The arguments of signals and slots are types, not variables.

    You passed t which is a variable and not a type.
    It's nice to be important but it's more important to be nice.

  14. #13

    Default Re: Signal and slot

    Thank a lot.

Similar Threads

  1. Replies: 8
    Last Post: 27th August 2009, 14:51
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  3. Replies: 12
    Last Post: 18th September 2008, 15:04
  4. Signal & Slot editor
    By Ishark in forum Qt Tools
    Replies: 4
    Last Post: 28th May 2008, 15:20
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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
  •  
Qt is a trademark of The Qt Company.