Qt的模型/视图架构

时间:2016-12-10 17:53:31

标签: qt linq-to-sql qtsql

在与数据库建立连接后,我编写了以下代码,但在执行后,内部单元格为空。为什么呢?

enum {
        name = 0,
        clas = 1,
        launched = 2
    };

      QSqlTableModel* model = new QSqlTableModel;
       model->setTable("ships");
       model->setSort(name, Qt::AscendingOrder);
       model->setHeaderData(name, Qt::Horizontal, "Name");
       model->setHeaderData(clas, Qt::Horizontal, "class");
       model->setHeaderData(launched, Qt::Horizontal, "launched");

       model->select();   

     QTableView *  view = new QTableView;   

           view->setModel(model);
           view->setSelectionMode(QAbstractItemView::SingleSelection);
           view->setSelectionBehavior(QAbstractItemView::SelectRows);
           view->resizeColumnsToContents();
           view->setEditTriggers(QAbstractItemView::NoEditTriggers);
           QHeaderView *header = view->horizontalHeader();
           header->setStretchLastSection(true);
           view->show(); 

0 个答案:

没有答案