Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transferring a string from one .cpp file to another

Tags:

c++

qt

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.

like image 406
dpopo Avatar asked Mar 08 '26 13:03

dpopo


1 Answers

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!

like image 122
frogatto Avatar answered Mar 11 '26 04:03

frogatto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!