我是在list类中做了一个界面,并绑定类槽函数;然后加到类mainwindow中,但是槽函数没有执行,但是connect返回值true说明已经办定成功了啊?为什么没有执行呢?槽函数我也声明了,初学者求拍醒啊。。。
我贴上源码吧!
// 这是类list的:
//----------------------------list.h
#ifndef LIST_H
#define LIST_H
#include
#include
#include
#include
#include
#include
class list : public QWidget
{
Q_OBJECT
public:
list();
QStringListModel *ml;
QListView *vl;
QPushButton *btn_insert;
QPushButton *btn_remove;
QWidget *qw;
QWidget *addUI();
QLineEdit *line;
public slots:
void l_insert();
};
#endif // LIST_H
//----------------------------list.cpp
list::list()
{
ml=new QStringListModel;
vl=new QListView;
btn_insert=new QPushButton("插入");
btn_remove=new QPushButton("删除");
qw=new QWidget;
line=new QLineEdit("insert:");
bool a=connect(btn_insert,SIGNAL(clicked()),this,SLOT(l_insert()));
qDebug()<<a<<endl;
}
QWidget * list::addUI(){
QStringList str;
str<<"通道1"<<"通道2";
ml->setStringList(str);
vl->setModel(ml);
QHBoxLayout *h1=new QHBoxLayout;
QFormLayout *f1=new QFormLayout;
h1->addWidget(btn_insert);
h1->addWidget(btn_remove);
f1->addRow(vl);
f1->addRow(line);
f1->addRow(h1);
qw->setLayout(f1);
return qw;
};
void list::l_insert(){
qDebug()<<"@@@@@";
QString str=line->text();
qDebug()<<"str"<
int row=vl->currentIndex().row();
QModelIndex index=ml->index(row);
ml->setData(index,str);
vl->setCurrentIndex(index);
vl->edit(index);
};
mainwindow.cpp // 只是调用此界面
tab=new QTabWidget;
QWidget *w1=new QWidget;
list l1;
w1=l1.addUI();
tab->addTab(w1,"QList");
setCentralWidget(tab);