Results 1 to 2 of 2

Thread: slots and signals

  1. #1
    Join Date
    Sep 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default slots and signals

    Hello
    any one can help to find the error

    i want when i click in the button the text changed
    Qt Code:
    1. #include <QApplication>
    2. #include <QPushButton>
    3.  
    4. void handleButton(QPushButton *m_bouton)
    5. {
    6. // change the text
    7. m_bouton->setText("Example");
    8. }
    9.  
    10. int main(int argc, char *argv[])
    11. {
    12. QApplication app(argc, argv);
    13.  
    14. QPushButton *m_bouton=new QPushButton("Salut les Zéros, la forme ?");
    15. m_bouton->show();
    16. QObject::connect(m_bouton, SIGNAL (clicked()), m_bouton, SLOT (handleButton(m_bouton)));
    17.  
    18.  
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 4th September 2016 at 17:49. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: slots and signals

    The clicked() signal does not have a QPushButton* argument, so the slot can't have one either.

    Argument types of signal and slot need to match.

    Also m_bouton doesn't have a slot called handleButton, see the documentation for QPushButton.

    You can use the function pointer based connect() with a functor or a lambda (if your compiler supports C++11) for a free standing function slot with context, or a QSignalMapper for adding the context to the signal and the function pointer based connect(), or a QSignalMapper and a receiver class for macro based connect() or a receiver object specific for the button and macro based connect.

    Cheers,
    _

Similar Threads

  1. Signals & slots
    By igoreshka3333 in forum Newbie
    Replies: 10
    Last Post: 20th December 2014, 17:49
  2. Qt signals/slots dll for non-Qt app
    By bareil76 in forum Qt Programming
    Replies: 3
    Last Post: 24th October 2014, 13:19
  3. Replies: 2
    Last Post: 18th April 2013, 12:15
  4. Signals and slots
    By sylvarant in forum Newbie
    Replies: 4
    Last Post: 11th September 2007, 15:48
  5. help with signals and slots
    By superutsav in forum Qt Programming
    Replies: 3
    Last Post: 4th May 2006, 12:49

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.