原因是每次setupUi()都会创建新的组件如pushbutton,你写在构造函数中的connect连接的是原先的button。
在setupUi()后重新connect signal 即可。
QMessageBox::about(this,tr("Welcome!"),tr("Wish you pleasant shopping!"));
QWidget *w5 = new QWidget;
fifthUi.setupUi(w5);
connect(fifthUi.pushButton1,SIGNAL(clicked()),this,SLOT(buy())); //添加这一行
w5->show();
this->close();