我是 Qt 新手(主要使用 Objective-C),所以我遇到了可能是新手问题。来自QDialog
我尝试打开的窗口QMainWindow
像这样:
this->close();
SQLWindow window;
window.receivePath(path); //Path for the .sqlite file
window.show()
QDialog
关闭,在几毫秒内我看到了一个新窗口,但它也关闭了。下边是QMainWindow
part:
SQLWindow::SQLWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::SQLWindow)
{
ui->setupUi(this);
this->initialSetup();
}
SQLWindow::~SQLWindow()
{
delete ui;
}
void SQLWindow::initialSetup()
{
ui->tableView->setSortingEnabled(true);
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
void SQLWindow::receivePath(QString path)
{
this->openDatabase(path);
}
void SQLWindow::openDatabase(QString path)
{
//Opening database just fine
}
您的窗口是一个局部变量,它在函数结束时被销毁,因此析构函数将其关闭。
你可以做的是创建SQLWindow
在堆上new SQLWindow
以及例如使用Qt::WA_DeleteOnClose
属性如图所示here.
或者,更好的设计可能是将对话框和窗口创建为局部变量main
函数并让 main 函数将路径从对话框传递到SQLWindow
,那么你不需要new
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)