Results 1 to 5 of 5

Thread: What is passed into SIGNAL/SLOT function parameters?

  1. #1
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default What is passed into SIGNAL/SLOT function parameters?

    What is passed into SIGNAL/SLOT function parameters?

    Qt Code:
    1. connect( lineEdit, SIGNAL( textChanged(const QString &) ),
    2. this, SLOT( enableFindButton(const QString &) ) );
    3.  
    4. void FindDialog::enableFindButton( const QString &text )
    5. {
    6. findButton->setEnabled( !text.isEmpty() );
    7. }
    To copy to clipboard, switch view to plain text mode 

    enableFindButton is called (by who exactly? The operating system?) but what is passed into const QString &? Obviously it's either going to be an empty string or not but what value does it hold? Do most if not all signals and slots of your own creation have to have a parameter?

  2. #2
    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: What is passed into SIGNAL/SLOT function parameters?

    The signals/slots will have parameter or not depending on what you need to achieve with them.

    The slot will be called when the signal is emitted, you will see in that example something like:
    Qt Code:
    1. emit textChanged(someString); //where someString is a QString, most likely written by the user in some lineedit
    To copy to clipboard, switch view to plain text mode 

    Recommended reading signal/slot documentation (documentation is a good companion for any book)

    LE: actually your lineEdit will emit the signal whenever it's text is changed
    Sorry i just saw that it's an signal of a QWidget (QLineEdit) not one of declared in your class...

  3. #3
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What is passed into SIGNAL/SLOT function parameters?

    But what if the slot is not called by an emit, by me specifically?

    EDIT: Ah, Zlatomir. So, lineEdit sends an emit....does it pass into the parameter whatever is inside the text field?

  4. #4
    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: What is passed into SIGNAL/SLOT function parameters?

    The slots can be called, just like any other member functions. Was that the answer?

    And the signals you declare (you don't define them) you emit with: emit YOUR_SIGNAL_NAME(); whenever is you need to signal something (depending on your application) and all the slots connected with that signal will be called.


    Added after 5 minutes:


    Quote Originally Posted by Plissken View Post
    EDIT: Ah, Zlatomir. So, lineEdit sends an emit....does it pass into the parameter whatever is inside the text field?
    Yep, i corrected that a little bit later, in the beggining i thougth the signal was declared by you, then i saw that is a signal of one QWidget...
    See the signal description in the documentation
    Last edited by Zlatomir; 20th January 2011 at 00:39.

  5. #5
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What is passed into SIGNAL/SLOT function parameters?

    Thank you.

Similar Threads

  1. Replies: 0
    Last Post: 24th October 2010, 19:09
  2. Replies: 3
    Last Post: 3rd May 2009, 14:15
  3. Slots & Signals w/ parameters passed by reference.
    By Wazman in forum Qt Programming
    Replies: 7
    Last Post: 20th December 2008, 00:13
  4. Replies: 2
    Last Post: 16th August 2007, 00:20
  5. Replies: 12
    Last Post: 14th June 2006, 09:24

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.