我尝试在程序中使用 QTableView。我已经在我开始的另一个测试项目中修复了模型中的所有错误。
现在,我尝试在我的主项目中插入模型和 QTableView,但与其他项目相比,QTableView 仅打开半秒钟,然后立即关闭!但是,相同的代码在测试项目中运行良好。
这是我在测试项目中的代码:
#include <QApplication>
#include <QTableView>
#include "start.h"
#include "mymodel.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableView tableView;
MyModel myModel(0);
tableView.setModel(&myModel);
tableView.setSelectionBehavior(QAbstractItemView::SelectRows);
tableView.show();
//Start w;
//w.show();
return a.exec();
}
这是主项目中的相关代码:
void Startseite::on_ButtonOK_clicked()
{
switch (ui->menuLeiste->currentIndex()) {
case 0:
{
QTableView tableview;
Model myModel(0);
tableview.setModel(&myModel);
tableview.setSelectionBehavior(QAbstractItemView::SelectRows);
tableview.show();
break;
}
case 1:
{
// other functions...
}
}
}
模型是一个 QAbstractTableModel。
有谁知道,为什么 TableView 关闭?
谢谢!