LaTj
5th September 2013, 05:48
I am making a database that adds a person's name and info. I am a newbie, so I will try to explain my problem.
I used the insertRows() function so the primeInser signal can be emmited. The problem is that it only executes only once. I am using an QSqlTableModel and QTableView to make the database.
//Here is the code on the constructor
nameModel = new QSqlTableModel(this);
nameModel->setTable("member");
nameModel->setEditStrategy(QSqlTableModel::OnFieldChange);
nameModel->setSort(Member_Name, Qt::AscendingOrder);
nameModel->setHeaderData(Member_Name, Qt::Horizontal, tr("Name"));
nameModel->setHeaderData(Member_Gender, Qt::Horizontal, tr("Gender"));
nameModel->setHeaderData(Member_DOB, Qt::Horizontal, tr("DOB"));
nameModel->setHeaderData(Member_PersonalInfo, Qt::Horizontal, tr("Personal Info"));
nameModel->select();
nameTableView = new QTableView;
nameTableView->setModel(nameModel);
nameTableView->setSelectionMode(QAbstractItemView::SingleSelectio n);
nameTableView->setSelectionBehavior(QAbstractItemView::SelectRows );
nameTableView->resizeColumnsToContents();
//After calling insertRows
int row = nameModel->rowCount();
nameModel->insertRows(row, 1);
//then my insertName signal is called
void MainForm::insertName(int row, QSqlRecord &record)
{
record = nameModel->record(row);
record.setValue("id", generateId("member"));
record.setValue("name", nameform->getNameText());
record.setValue("gender", nameform->getGenderText());
record.setValue("dob", nameform->getDOBDate());
record.setValue("persinfo", nameform->getPrivacyText());
}
//my problem is that it only creates and displays the first row and on the second insertRows(row, 1) it does not emit the primeInsert() and it only displays the
//first row.
//If anyone could help me, it would be greatly appreciated.
I used the insertRows() function so the primeInser signal can be emmited. The problem is that it only executes only once. I am using an QSqlTableModel and QTableView to make the database.
//Here is the code on the constructor
nameModel = new QSqlTableModel(this);
nameModel->setTable("member");
nameModel->setEditStrategy(QSqlTableModel::OnFieldChange);
nameModel->setSort(Member_Name, Qt::AscendingOrder);
nameModel->setHeaderData(Member_Name, Qt::Horizontal, tr("Name"));
nameModel->setHeaderData(Member_Gender, Qt::Horizontal, tr("Gender"));
nameModel->setHeaderData(Member_DOB, Qt::Horizontal, tr("DOB"));
nameModel->setHeaderData(Member_PersonalInfo, Qt::Horizontal, tr("Personal Info"));
nameModel->select();
nameTableView = new QTableView;
nameTableView->setModel(nameModel);
nameTableView->setSelectionMode(QAbstractItemView::SingleSelectio n);
nameTableView->setSelectionBehavior(QAbstractItemView::SelectRows );
nameTableView->resizeColumnsToContents();
//After calling insertRows
int row = nameModel->rowCount();
nameModel->insertRows(row, 1);
//then my insertName signal is called
void MainForm::insertName(int row, QSqlRecord &record)
{
record = nameModel->record(row);
record.setValue("id", generateId("member"));
record.setValue("name", nameform->getNameText());
record.setValue("gender", nameform->getGenderText());
record.setValue("dob", nameform->getDOBDate());
record.setValue("persinfo", nameform->getPrivacyText());
}
//my problem is that it only creates and displays the first row and on the second insertRows(row, 1) it does not emit the primeInsert() and it only displays the
//first row.
//If anyone could help me, it would be greatly appreciated.