PDA

View Full Version : Object::connect: No such slot QPushButton::enable()



nthung
27th October 2011, 12:02
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QList>
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private:
Ui::MainWindow *ui;
public slots:
void enable();
};

#endif // MAINWINDOW_H


#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QStringListModel"
#include <QThread>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->comboBox, SIGNAL(editTextChanged(QString)),ui->pushButton,SLOT(enable()));
}

MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::enable(){
ui->pushButton->setEnabled(true);
}

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

Kumosan
27th October 2011, 12:18
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'. :-)

ChrisW67
28th October 2011, 01:05
Ask yourself, "Which object contains the slot enable()?" It is this object you should be using in your connect() call.

nthung
28th October 2011, 05:31
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:


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

ChrisW67
28th October 2011, 06:09
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.