Results 1 to 5 of 5

Thread: Connecting a Button Click signal to member function

  1. #1
    Join Date
    Jul 2009
    Posts
    7
    Thanks
    1
    Platforms
    Windows

    Question Connecting a Button Click signal to member function

    As per the Qt docs, We can connect signals to slots in a many-to-many fashion.

    But lets say I have a member function void foo() and NOT declared in slots declaration section, and its just a member function. Then Can i connect the buton click SIGNAL to foo() member function ? Like ...
    Qt Code:
    1. connect(myPushButton, SIGNAL(clicked()),this, SLOT(foo()));
    To copy to clipboard, switch view to plain text mode 

    When I've declared void foo() in private slots: section, its getting called properly. But when I'm declaring void foo() in private: section, its not getting called.

    So, Is there any way we connect a signal to a member function without declaring it as a slot member function ?

    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Connecting a Button Click signal to member function

    Methods are declared as slots to be able to be connected to signals. Thus the answer that you can't connect to a method which is not a slot.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Connecting a Button Click signal to member function

    if foo() so much valuable that it cant be slot.. then why not use a third func() and call foo() from there.

  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: Connecting a Button Click signal to member function

    Don't forget that you can always call a slot as a normal function call. Defining a function as a slot just registers it in the meta object data so you can connect to it.

  5. #5
    Join Date
    Jul 2009
    Posts
    7
    Thanks
    1
    Platforms
    Windows

    Default Re: Connecting a Button Click signal to member function

    Thank you.
    I understood what you all said but I was asking to clarify it.
    Else there is no harm for me to put foo() (my valuable fn :-) ) in private slots: section.

Similar Threads

  1. button click in webview
    By mind_freak in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2009, 14:48
  2. How to call a function when i clic a button?
    By trend900 in forum Newbie
    Replies: 2
    Last Post: 22nd January 2009, 17:40
  3. how to know which button emit the signal?
    By coder1985 in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2008, 15:26
  4. Connecting signal to button
    By steg90 in forum Qt Programming
    Replies: 8
    Last Post: 13th December 2007, 11:37
  5. Push button double click
    By curtisw in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 17:40

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.