PDA

View Full Version : Monitoring changing data of a database via QSqlRelationalmodel and QDatawidgetMapper



kingJack
20th December 2013, 12:20
Hello,

i try to display data of a database record which changes from outside.
I use a QSqlRelationalTableModel frequently calling select() to refresh the actual database data.
The Model is connected To a QDataWidgetMapper who has several QLabels mapped to.
The datafields are displayed correctly but they don't refresh, when data changes from outside.


A QTableView, connected to the Model, displays the refreshed data, but the labels don't.



m_pModel = new QSqlRelationalTableModel(this);

m_pModel->setTable("Auftraege");
m_pModel->setSort(DB_AUFTRAG_ID, Qt::AscendingOrder);
m_pModel->setRelation(DB_AUFTRAG_KUNDENNUMMER, QSqlRelation("Kunde", 0, "ORT"));
m_pModel->select();

m_pMapper = new QDataWidgetMapper(this);
m_pMapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
m_pMapper->setModel(m_pModel);
//m_pMapper->setItemDelegate(new QSqlRelationalDelegate(this));
m_pMapper->addMapping(ui->m_lbTaskNr, DB_AUFTRAG_NUMMER, "text");
m_pMapper->addMapping(ui->m_lbName1, DB_AUFTRAG_KUNDENNAME1, "text");


void MASK_AUFTRAG_HAUPT::vRefreshFromDB()
{
m_pModel->select();
m_pMapper->revert(); //doesn't work, why?
}


is there a way to provide frequently refreshing, using a QDataWidgetMapper?

kingJack
6th January 2014, 15:30
doesn't anyone have an idea?

when I close the form and reopen it, the widgets show the actual values of the database, but I couldn manage to refresh the open form frequently, when the database values are changing from outside!