Results 1 to 5 of 5

Thread: Object::connect: No such slot QPushButton::enable()

  1. #1
    Join Date
    Nov 2009
    Posts
    59
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Object::connect: No such slot QPushButton::enable()

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QList>
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17.  
    18. private:
    19. Ui::MainWindow *ui;
    20. public slots:
    21. void enable();
    22. };
    23.  
    24. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "QStringListModel"
    4. #include <QThread>
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::MainWindow)
    8. {
    9. ui->setupUi(this);
    10. connect(ui->comboBox, SIGNAL(editTextChanged(QString)),ui->pushButton,SLOT(enable()));
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    17. void MainWindow::enable(){
    18. ui->pushButton->setEnabled(true);
    19. }
    To copy to clipboard, switch view to plain text mode 
    after run this code is give me errors
    Object::connect: No such slot QPushButton::enable()
    my program is when user chang text in combobox then pushbutton is enable, but it can be enable
    thanks

  2. #2
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Object::connect: No such slot QPushButton::enable()

    You define a SLOT 'enable' in your main window. But you try to connect this slot as if you did it in your pushbutton. Nope, pushbutton has no slot 'enable'. :-)

  3. The following user says thank you to Kumosan for this useful post:

    nthung (28th October 2011)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Object::connect: No such slot QPushButton::enable()

    Ask yourself, "Which object contains the slot enable()?" It is this object you should be using in your connect() call.

  5. The following user says thank you to ChrisW67 for this useful post:

    nthung (28th October 2011)

  6. #4
    Join Date
    Nov 2009
    Posts
    59
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Object::connect: No such slot QPushButton::enable()

    Thanks for answers.
    I understand the problem when it raises error. and I don't know how to fix it
    But now, I want to know how do I add new slots to pushbutton.
    Could you fix it for me
    thanks


    Added after 1 54 minutes:


    Quote Originally Posted by ChrisW67 View Post
    Ask yourself, "Which object contains the slot enable()?" It is this object you should be using in your connect() call.
    it means that I can't add new Slot to pushbutton and the other widget, can be it?
    Thanks
    Last edited by nthung; 28th October 2011 at 04:31.

  7. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Object::connect: No such slot QPushButton::enable()

    To add new slots to a QPushButton you must derive your own class from QPushButton. The new slot is available to all instances of that derived class. You have not done that for QPushButton, but you have added a slot to the base QMainWindow in exactly the same way.

    The slot you have created in your MainWindow class manipulates a particular push button when called... the problem is that your connect() call does not connect to the MainWindow instance that contains the slot.

  8. The following user says thank you to ChrisW67 for this useful post:

    nthung (28th October 2011)

Similar Threads

  1. Anoying problem, Object::connect: No such slot
    By Aslund in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2011, 08:09
  2. connect a qpushbutton a slot
    By Lycus HackerEmo in forum Newbie
    Replies: 13
    Last Post: 29th March 2010, 09:14
  3. Connect signal from base to slot of sub-sub-object
    By donglebob in forum Qt Programming
    Replies: 15
    Last Post: 30th October 2008, 19:54
  4. Object::connect: Parentheses expected, slot...
    By bnilsson in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2008, 15:02
  5. Replies: 3
    Last Post: 24th September 2007, 08:20

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.