Thanks for the suggestion, I tried passing in the query string to object via its "prepare" function (rather than in the constructor as above), and I have the same result. A sqlite-journal file is created, and the program returns without warning or error.
One thing worth noting is that, when my QSqlQueryModel repopulates the view after the query, I get a duplicate of the last entry when recreating all the table rows. For example, if I have a user table that reads:
John
Fred
Mark
And I execute delete on Mark, My table repopulates like this:
John
Fred
Fred
{
QString userQuery
= "SELECT * FROM users";
users->setQuery(userQuery, db);
return users;
}
void TbxUsers::populateUserList( void )
{
// Remove out all rows in the table.
for( int i = 0; i < m_ui->tableWidget->rowCount(); i++)
m_ui->tableWidget->removeRow(i);
// Get a model of users contained in the table.
// Have to use QModelIndex to get the record count.
int numUsers = users->rowCount(index);
for(int i = 0; i < numUsers; i++)
{
m_ui->tableWidget->insertRow(i);
m_ui->tableWidget->setItem(i,0,username);
}
}
QSqlQueryModel * getUsers()
{
QSqlQueryModel * users = new QSqlQueryModel();
QString userQuery = "SELECT * FROM users";
users->setQuery(userQuery, db);
return users;
}
void TbxUsers::populateUserList( void )
{
// Remove out all rows in the table.
for( int i = 0; i < m_ui->tableWidget->rowCount(); i++)
m_ui->tableWidget->removeRow(i);
// Get a model of users contained in the table.
QSqlQueryModel * users = getUsers();
// Have to use QModelIndex to get the record count.
QModelIndex index;
int numUsers = users->rowCount(index);
for(int i = 0; i < numUsers; i++)
{
QTableWidgetItem *username;
username = new QTableWidgetItem(users->record(i).value("username").toString());
m_ui->tableWidget->insertRow(i);
m_ui->tableWidget->setItem(i,0,username);
}
}
To copy to clipboard, switch view to plain text mode
Something really strange is going on here. I considered the possibility of a corrupt database, but I've been using the firefox plugin to connect and manage my database outside of Qt, and things always seem to work well with it.
PS: Adding transaction code in getUsers() didn't seem to help the matter either, though I didn't add transaction logic to every place in the software I use the QSqlQueryModel.
Hmmm....
Bookmarks