自定义槽 No such slot
诸位好。最近在做qt,自定义槽的时候,出现如下错误。先把代码贴出了,请各位老师,过目。
头文件:mainwindow.h
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QtGui/QLineEdit>namespace Ui { class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECTpublic: explicit MainWindow(QWidget *parent = 0); ~MainWindow();private: Ui::MainWindow *ui; QVector<QLineEdit*> lines; QStringList paths;public slots: void upload2Ftp(); void inputFinish(QString,int); };#endif // MAINWINDOW_H
#include "mainwindow.h"#include "ui_mainwindow.h"#include <QDebug>#include <QObject>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); lines.append(ui->lineEdit_0); lines.append(ui->lineEdit_1); lines.append(ui->lineEdit_2); lines.append(ui->lineEdit_3); lines.append(ui->lineEdit_4); ui->progressBar->setRange(0,100); ui->progressBar->setValue(0); for(int i=0;i<lines.size();i++){ QLineEdit* edit = lines.at(i); connect(edit,SIGNAL(editingFinished()),this->centralWidget(),SLOT(this->inputFinish(edit->text(),i))); } connect(ui->pushButton_0,SIGNAL(clicked()),this->centralWidget(),SLOT(this->upload2Ftp()));}MainWindow::~MainWindow() { delete ui;}void MainWindow::inputFinish(QString path,int index) { paths.replace(index,path);}void MainWindow::upload2Ftp(){ for(int i=0;i<lines.size();i++){ qDebug()<<paths.at(i); }}
#include <QtGui/QApplication>#include "mainwindow.h"#include <QtGui/QPushButton>#include <QtGui/QLineEdit>int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec();}
for(int i=0;i<lines.size();i++){ QLineEdit* edit = lines.at(i); connect(edit,SIGNAL(editingFinished()), [color=#FF0000]edit[/color] ,SLOT(this->inputFinish(edit->text(),i))); }
[解决办法]
void QLineEdit::textChanged ( const QString & text ) [signal]
问题在于,你写的信号,QLineEdit里没有,只有上面的那个,区别是有一个参数。