C++ (Qt)var = new ClassName();
C++ (Qt)private: ClassName *var;
ASSERT failure in QVector<T>::at: "index out of range", file ../../include/QtCore/../../src/corelib/tools/qvector.h, line 327
C++ (Qt)#include "mainwindow.h"#include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindowClass){ ui->setupUi(this); model1 = new QSqlTableModel; proxyModel = new QSortFilterProxyModel; db = QSqlDatabase::addDatabase("QMYSQL"); db.setDatabaseName( "organization" ); db.setHostName("localhost"); db.setUserName("root"); db.setPassword("trenkinan90"); if(db.open()) { QTextCodec::setCodecForCStrings(QTextCodec::codecForName("windows-1251")); model1->setTable("peoples4"); model1->select(); ui->mytable->setModel(model1); ui->mytable->setEditTriggers(QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed); row = model1->rowCount(); proxyModel->setSourceModel(model1); ui->mytable->setModel(proxyModel); QTextCodec::setCodecForTr(QTextCodec::codecForName("windows-1251")); model1->setHeaderData(6, Qt::Horizontal, tr("Женат/замужем")); model1->setHeaderData(8, Qt::Horizontal, tr("Дата рождения")); view.setAlternatingRowColors(true); view.setModel(model1); QSqlQuery temp; } else qDebug()<<"Error in opening"<<db.lastError();} MainWindow::~MainWindow(){ delete ui;} void MainWindow::on_create_triggered(){ model1 = new QSqlTableModel; model1->insertRow(row); model1->submitAll();}
C++ (Qt)#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QAction>#include<QMenu>#include<QtSql> #include <QModelIndex> #include <QTableView> #include <QSortFilterProxyModel>#include <QtGui/QMainWindow> namespace Ui{ class MainWindowClass;} class MainWindow : public QMainWindow{ Q_OBJECT public: MainWindow(QWidget *parent = 0); ~MainWindow(); int row; QTableView view;QSqlRecord rec;QModelIndex insertIndex; QSqlDatabase db; QMenu menu; private: Ui::MainWindowClass *ui; QSqlTableModel *model1; QSortFilterProxyModel *proxyModel; private slots: void on_create_triggered();};