Login::Login(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::Login)
{
ui->setupUi(this);
。。。
}
Login::~Login()
{
qDebug()<< "inner destrucor...";
delete ui;
}
Login::Jump123(){
//Mainpage *mp = new... // 另一個界面
//mp.show(); // 大概這意思
this->close();
qDebug()<< "inner Jump...";
}
運行后,頁面跳轉問題的,但是沒有進入login的解構式,只有關掉視窗才能呼叫,那close與hide有啥區別,甚至用了this->destory();同樣沒有銷毀
另外,這個close還是QWidget的一個槽,頁面跳轉,怎么銷毀當前頁面,做到真正的跳轉?
[slot] bool QWidget::close()
Closes this widget. Returns true if the widget was closed; otherwise returns false.
First it sends the widget a QCloseEvent. The widget is hidden if it accepts the close event. If it ignores the event, nothing happens. The default implementation of QWidget::closeEvent() accepts the close event.
If the widget has the Qt::WA_DeleteOnClose flag, the widget is also deleted. A close events is delivered to the widget no matter if the widget is visible or not.
The QApplication::lastWindowClosed() signal is emitted when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus.
uj5u.com熱心網友回復:
你好,我試一下加了setAttribute(Qt::WA_DeleteOnClose);可以#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
close();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/239312.html
標籤:Qt
