Answer the question
In order to leave comments, you need to log in
QT: how to update the database after query execution?
There was a problem that after entering data into tables, before closing the program, they are not displayed in other tables.
For example, there is a reference table in which I enter data and write it to the database (yes, they are recorded in the database, I checked this), then I open a form that should use this data for itself, but they are not displayed there, that is, after saving there is no data update.
A little about the structure of the program:
The following variables for windows are declared in the mainwindow.h file:
genusPlantD* genPlantD;
researcherD* researchD;
openProjectD* openPrD;
addEditProject* aeProj; //добавление/редактирование проекта
void MainWindow::ht_genusPlants()
{
genPlantD = new genusPlantD();
genPlantD->show();
}
void db::PlantStore(QString name, QString descr, QString gps, QString typeP, QString genusP, QString age, QString cipher, QString variety, QString whoAdded, QDate dateAdded)
{
qDebug() << "db::PlantStore .....";
QSqlQuery* sq = new QSqlQuery(sdb->getDB());
strQuery = "INSERT INTO plants (title, description, gps, type_plant_id, genus_plant_id,"
"age, cipher, variety, who_added_id, date_added) VALUES ('"+name+"','"+descr+"','"+
gps+"','"+typeP+"','"+genusP+"','"+age+"','"+cipher+"','"+variety+
"','"+whoAdded+"','"+dateAdded.toString("yyyy-MM-dd")+"')";
sq->exec(strQuery);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
.....
openPrD = new openProjectD(); //для открытия проекта
aeProj = new addEditProject();
.......
connect(aeProj,SIGNAL(sendOnlyCreateProjectSignal()),
this, SLOT(afterCreateNewProject()));
}
void MainWindow::afterCreateNewProject()
{
openPrD = new openProjectD();
}
QMultiMap<QString, QString> db::researchList_Term()
{
QString id, fio;
QSqlQuery *p_Query = new QSqlQuery("SELECT id, fio FROM researcher", sdb->getDB());
QSqlRecord record;
QMultiMap<QString,QString> rMap;
while(p_Query->next()){
record=p_Query->record();
id=record.value("id").toString();
fio=record.value("fio").toString();
rMap.insert(id, fio);
}
return rMap;
}
void addEditProject::reportResearcher()
{
researchMap = myDB->researchList_Term();
QMultiMap<QString, QString>::iterator it = researchMap.begin();
for (;it != researchMap.end(); ++it) {
ui->researcher_cb->addItem(it.value());
ui->researcher2_cb->addItem(it.key());
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question