我在Qt example(phonon,qmusicplayer)中加了一个login画面,在login画面按下确认按钮后,显示qmusicplayer的画面,但是qmusicplayer画面一闪就未出现,代码如下
int main(int argv, char **args)
{
QApplication app(argv, args);
app.setApplicationName("Music Player");
app.setQuitOnLastWindowClosed(true);
Login login;
login.show();
return app.exec();
}
Login::Login()
{
QHBoxLayout* hlayerout = new QHBoxLayout();
QLabel* label = new QLabel("name: ");
QLineEdit* nameedit = new QLineEdit();
hlayerout->addStretch();
hlayerout->addWidget(label);
hlayerout->addWidget(nameedit);
QHBoxLayout* hlayerout1 = new QHBoxLayout();
QLabel* label1 = new QLabel("password: ");
QLineEdit* nameedit1 = new QLineEdit();
hlayerout1->addStretch();;
hlayerout1->addWidget(label1);
hlayerout1->addWidget(nameedit1);
QHBoxLayout* hlayerout2 = new QHBoxLayout();
QPushButton* confirmbutton = new QPushButton("Ok");
QPushButton* cancelbutton = new QPushButton("Cancel");
hlayerout2->addStretch();;
hlayerout2->addWidget(confirmbutton);
hlayerout2->addWidget(cancelbutton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(hlayerout);
mainLayout->addLayout(hlayerout1);
mainLayout->addLayout(hlayerout2);
mainLayout->setSpacing(0);
setLayout(mainLayout);
connect(confirmbutton,SIGNAL(clicked()),this,SLOT(slotShowWindow()));
}
void Login::slotShowWindow()
{
close();
MainWindow window;
window.show();
}