答案 0 :(得分:1)
答案 1 :(得分:0)
当我开始你的程序时。我得到这个运行时qt warnigs:
Object::connect: No such slot QWidget::open() in question.h:44
Object::connect: No such slot QWidget::back() in question.h:45
因此您的连接无效。插槽在Myclass中定义,而不是在window1和window2中定义。替换为
QObject::connect(b1,SIGNAL(clicked()),this,SLOT(open()));
QObject::connect(b2,SIGNAL(clicked()),this,SLOT(back()));
或更短:
connect(b1,SIGNAL(clicked()),this,SLOT(open()));
connect(b2,SIGNAL(clicked()),this,SLOT(back()));
你得到了预期的行为。