Jask
Jask

Reputation: 680

How exactly do i use beginInsertRows()?

When i use this function like below.

beginInsertRows()

beginInsertRows: identifier not found

I'm new to c++. How do i call this function? I'm including QtSql. Should i include something special?

EDIT: I've searched for solutions and all of them point to using this function as i posted. But i'm getting this error.

    this->sqlModel2 = new QSqlQueryModel();
    sqlTableModel = new QSqlTableModel(this);
    sqlTableModel->setTable("mytable");
    sqlTableModel->select();

    qDebug()<< sqlTableModel->lastError().text();

    ui->listView->setModel(sqlTableModel);
    ui->listView->setModelColumn(1);



            QString name;
            name= " My name";
            QSqlQuery qryInsert;
            QString mInsert "INSERT INTO mytable (:name) VALUES (:name)";

            qryInsert.prepare(mInsert);

            qryInsert.bindValue(":name",name);
            beginInsertRows(QModelIndex(),0,1) ;
            if(qryInsert.exec()){
                      qDebug()<<"Inserted";
                      result = "inserted";


                  }else{
                      qDebug()<<"Error inserting = "<<qry.lastError().text();
                  }
             endInsertRows();

Upvotes: 2

Views: 4698

Answers (1)

Johny
Johny

Reputation: 1997

beginInsertRows() is method of QAbstractItemModel and it is protected. So you can call it only when you subclass QAbstractItemModel inside of its methods. More info here.

Upvotes: 8

Related Questions