自定义的槽无响应
MainWindow里用stackedWidget管理了pView,pReview两个界面,可以同个按钮切换
创建如下
MainWindow::MainWindow(Connector* Conn, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
pReview(new Ui::Review),
pView(new Ui::View),
{
ui->setupUi(this);
pViewWidget = new QWidget(ui->stackedWidget);
pReviewWidget = new QWidget(ui->stackedWidget);
pView->setupUi(pViewWidget);
pReview->setupUi(pReviewWidget);
ui->stackedWidget->addWidget(pViewWidget);
ui->stackedWidget->addWidget(pReviewWidget);
setCentralWidget(ui->stackedWidget);
ui->stackedWidget->setCurrentIndex(2);
}
View 里有个按钮它的clicked是连接到AddNode的,但是点了AddNode没有响应
class View : public QWidget
{
Q_OBJECT
public:
explicit View(QWidget *parent = 0);
~View();
public slots:
void AddNode(void);
private:
Ui::View *ui;
};
View::View(QWidget *parent) :
QWidget(parent),
ui(new Ui::View)
{
QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(AddNode()));
ui->setupUi(this);
}
void View::AddNode(void)
{
QMessageBox::about(NULL, "dd", "dsdf");
}
View 里有个按钮pushButton
但是点了没有响应
[解决办法]
打断点调试一下。
[解决办法]
看一下connect返回值是true吗
[解决办法]
QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(AddNode()));
ui->setupUi(this); 改成:
ui->setupUi(this);
QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(AddNode()));