Good evening, I working on a project that requires me to use a string variable in one .cpp file and same string variable in the next .cpp file. This is my patientdatabase.cpp:
void patientDatabase::on_tableView_view_activated(const QModelIndex &index)
{
QString value = ui->tableView_view->model()->data(index).toString();
patientR.connOpen();
QSqlQuery qry;
qry.prepare("select * from imageTable where PatientId = '"+value+"'");
if (qry.exec()){
IVDB *x = new IVDB;
x->show();
}
This function basically changes windows to IVBD whenever I click on patientId on the table provided in my patientDatabase and now I need the string 'value' in my IVBD.cpp
QSqlQuery *qry = new QSqlQuery(registration.db);
qry->prepare("select * from imageTable where PatientId ='"+value+"'"); // this string 'value; is from the last .cpp file
I dont want to use global variables but stuck here and not sure how to approach it.
The best solution I can think of would be using signals and slots. In on_tableView_view_activated you should emit a signal and catch it in IVBD.cpp.
Using global variables doen't sound good, though it works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With