Object::connect: No such slot QPushButton::enable()
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QList>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
public slots:
void enable();
};
#endif // MAINWINDOW_H
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QStringListModel"
#include <QThread>
MainWindow
::MainWindow(QWidget *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
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'. :-)
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.
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
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
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.