我的堆叠小部件中有 2 个自定义小部件,我希望能够从一个更改为另一个,我按下一个按钮,但是当我当前单击它时,程序就会终止。
这是第一个自定义小部件 .cpp:
#include "loginpage.h"
#include "ui_loginpage.h"
#include "mainwindow.h"
#include "mainpage.h"
#include "QtGui"
LoginPage::LoginPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::LoginPage)
{
ui->setupUi(this);
connect(ui->loginPushButton, SIGNAL(clicked()), this, SLOT(doLogin()));
}
LoginPage::~LoginPage()
{
delete ui;
}
QString LoginPage::getUsername()
{
QString userName = ui->usernameLineEdit->text();
return userName;
}
QString LoginPage::getPassword()
{
QString passWord = ui->passwordLineEdit->text();
return passWord;
}
void LoginPage::doLogin()
{
QString username = getUsername();
QString password = getPassword();
bool check = checkCredentials(password, username);
if(check == true)
{
MainWindow *main;
main = new MainWindow;
main->test();
}else
{
QMessageBox::information(this, tr("incorrect"), tr("incorrect"));
}
}
...
这是主窗口.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "loginpage.h"
#include "ui_loginpage.h"
#include "mainpage.h"
#include <QtGui>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::test()
{
ui->stackedWidget->setCurrentIndex(1);
}
任何帮助表示赞赏