PDA

View Full Version : Debug says vaiable is empty but it isn't



vitalic
15th May 2020, 13:17
Hallo,

my program is split into several cpp and h files.

The GUI window is in dialog.cpp and dialog.h

The scan is in scan.cpp and scan. h

Save is in file.cpp and file.h

Scan is storing the results in a public QVector. When i hit a button in GUI i can see the output of QVector in the debug. When I hit save, nothing from the QVector is saved. Debugger shows QVector empty.

dialog.h


private:
Ui::Dialog *ui;
FM_rds mRds;
Scan mScan;
Tune mTune;
Mute mMute;
File mFile;


dialog.cpp (show content of QVector in Debug and save button)



void Dialog::on_pushButton_clicked()
{
qDebug() << "dab_vev_vec: " << mScan.dab_vec_vec;
}

void Dialog::on_pushButton_2_clicked()
{
mFile.dab_write_file();
}


file.h


#include <scan.h>

private:

Scan mScan;


file.cpp


for(int i = 0; i < mScan.dab_vec_vec.size(); i++){

dab_vec_vec_to_line = mScan.dab_vec_vec[i][0] + "," + mScan.dab_vec_vec[i][1] + "," + mScan.dab_vec_vec[i][2] + "," + mScan.dab_vec_vec[i][3];
qDebug() << "i: " << i << "dabvecvectoline: " << dab_vec_vec_to_line;
unsort_list.append(dab_vec_vec_to_line);
}


scan.h


public:

QVector<QVector<QString>> dab_vec_vec;

Lesiok
15th May 2020, 14:29
mScan in dialog,h and file.h is not the same object.

vitalic
15th May 2020, 16:42
Ok, how can I access the variable for File else? I wanted to avoid using a global variable.

d_stranz
15th May 2020, 17:35
Keep mScan in one class (your File class, for example). Add a setScans() method to your Dialog class to copy this data into the Dialog class instance before your call to exec(). Or keep it in your Dialog class and pass it as an argument to File:: dab_write_file().