PDA

View Full Version : Listing a column of a table to a QListWidget



Luc4
2nd October 2010, 15:24
Hi! I have a SQLite database with a table names monitored_directories. I would like to list the column original_path of this table in a QListWidget, where I can then edit the elements to upgrade my database. After reading documentation and examples I came up with this:


tableModel = new QSqlRelationalTableModel(this, LBTGlobals::getInstance()->dbManager->db);
tableModel->setTable("monitored_directories");
tableModel->select();
mapper = new QDataWidgetMapper(this);
mapper->setModel(tableModel);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->addMapping(listDir, tableModel->fieldIndex("original_path"));
mapper->toFirst();

The QListWidet listDir is empty, event if I have records in the table. What am I doing wrong?
Thanks for any advice!

Luc4
2nd October 2010, 20:21
Appearantly, almost everything was wrong :) This is how I did it:

tableModel = new QSqlTableModel(this, LBTGlobals::getInstance()->dbManager->db);
tableModel->setTable("monitored_directories");
tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
tableModel->select();
listDir->setModel(tableModel);
listDir->setModelColumn(1);