我是Qt的新手(主要使用Objective-C),所以我可能遇到了新手问题。从QDialog
窗口中,我尝试QMainWindow
像这样打开:
this->close();
SQLWindow window;
window.receivePath(path); //Path for the .sqlite file
window.show()
QDialog
关闭,一毫秒后,我看到了新窗口的一瞥,但它也关闭了。以下是QMainWindow
部分:
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
所示的属性。
或者,更好的设计可能是将对话框和窗口都创建为main
函数的局部变量,然后让主函数将对话框和路径的路径传递给SQLWindow
,那么就不需要了new
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句