windsword
25th August 2009, 12:57
Hello,
I want to automatically refresh my table, after I add a new record to the database.
I use a button to bring up a dialog form, in the "accept" button slot I'd like to refresh it before
executing the "accept()" function. But I get an error message that the
model is not defined in this class.
void AddClientForm::addclient2db_accept()
{ // this is the slot called to accept the entry and INSERT it into the desired table
.... code adding data to db record ...
model->clear();
model->setQuery("SELECT FirstName,LastName,ClientID FROM Clients");
model->setHeaderData(0,Qt::Horizontal, tr("First"));
model->setHeaderData(1,Qt::Horizontal, tr("Last Name"));
model->setHeaderData(2,Qt::Horizontal, tr("Client ID"));
accept();
}
model is defined in another class, but the above slot is define as shown in this header file:
/* AddClientForm - Add a new client to the database */
class AddClientForm : public QDialog
{
Q_OBJECT
public:
AddClientForm(QWidget *parent=0);
private slots:
void addclientform_reset();
void addclient2db_accept();
Do I need to inherit the parent class (where the button to add a new record is defined)?
Reference:
http://www.qtcentre.org/forum/f-qt-programming-2/t-how-can-i-refresh-qsqlquerymodel-21742.html
I want to automatically refresh my table, after I add a new record to the database.
I use a button to bring up a dialog form, in the "accept" button slot I'd like to refresh it before
executing the "accept()" function. But I get an error message that the
model is not defined in this class.
void AddClientForm::addclient2db_accept()
{ // this is the slot called to accept the entry and INSERT it into the desired table
.... code adding data to db record ...
model->clear();
model->setQuery("SELECT FirstName,LastName,ClientID FROM Clients");
model->setHeaderData(0,Qt::Horizontal, tr("First"));
model->setHeaderData(1,Qt::Horizontal, tr("Last Name"));
model->setHeaderData(2,Qt::Horizontal, tr("Client ID"));
accept();
}
model is defined in another class, but the above slot is define as shown in this header file:
/* AddClientForm - Add a new client to the database */
class AddClientForm : public QDialog
{
Q_OBJECT
public:
AddClientForm(QWidget *parent=0);
private slots:
void addclientform_reset();
void addclient2db_accept();
Do I need to inherit the parent class (where the button to add a new record is defined)?
Reference:
http://www.qtcentre.org/forum/f-qt-programming-2/t-how-can-i-refresh-qsqlquerymodel-21742.html