Hello everyone, I'm new to QT/C++ and I'm probably missing something essential and I can't make it to work.

I explain a bit.

I have 2 classes (*MainWindow.cpp/.h* and *SimulationTask.cpp/.h*).

MainWindow got a Menu that's using some variables to load via SQL the info.
Once user has clicked the last item on the list, it loads from SQL database a string with the name of our new variable, called tablename.

Now we have a second window, called SimulationTask that needs the variable tablename, but every time I use it, it uses it with its default value defined in mainwindow.h, instead of the actual value, as we did get in our mainwindow.cpp.

The code is long already, I will show you the essential parts so you can contrast.

Qt Code:
  1. //Get table method(at MainWindow.cpp)
  2.  
  3. QString MainWindow::getTableName()
  4.  
  5. connOpen();
  6. QSqlQuery query;
  7. query.prepare("SELECT candata_table,bitrate "
  8. "FROM system_list, maker_data "
  9. "WHERE system_list.specific_id=maker_data.specific_id "
  10. "AND system_list.specific_id="
  11. "(SELECT maker_data.specific_id FROM maker_data WHERE maker_data.manufacturer='"+varmnf+"' AND maker_data.model='"+varmodel+"' AND maker_data.year='"+varyear+"')");
  12. query.exec();
  13. query.first();
  14. connClose();
  15. tablename = query.value(0).toString();
  16.  
  17. qDebug() << (query.lastQuery());
  18.  
  19. return tablename;
To copy to clipboard, switch view to plain text mode 


If I call it on my MainWindow.cpp class, in a pushbutton for example, it does load values in Sql query (**varmnf , varmodel, varyear**) perfectly and it returns tablename without problem, but if I call it from my simulationTask.cpp, it get initializacion values for varmnf , varmodel, varyear, so obviously, the query doesnt throw any result, and tablename either.


Qt Code:
  1. #include "mainwindow.h"
  2. //TABLE NAME (at simulationstask.cpp)
  3. MainWindow mainwindow;
  4.  
  5. mainwindow.getTableName(); // --> This is returning tablename = ''
  6. qDebug() << ("Hello");
  7. qDebug() << (tablename);
To copy to clipboard, switch view to plain text mode 

**Console Output**
[Console Log image][1]


[1]: http://i.stack.imgur.com/ZADL6.jpg


This is my MainWindow.h:
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include "simulationtask.h"
  6.  
  7. #define debugprefix << __LINE__ << " "
  8. namespace Ui {
  9. class MainWindow;
  10. }
  11.  
  12. class MainWindow : public QMainWindow
  13. {
  14. Q_OBJECT
  15.  
  16.  
  17. public:
  18.  
  19. QString getTableName();
  20.  
  21. //FUNCTIONS VARIABLES
  22.  
  23. QString varmnf;
  24. QString varmodel;
  25. QString varyear;
  26. QString tablename;
  27. QString tablenameUpdated;
  28. QString bitrate;
  29. QString varsystem;
To copy to clipboard, switch view to plain text mode 

This is part of my MainWindow.cpp:

Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QMessageBox>
  4. #include "simulationtask.h"
  5.  
  6. void MainWindow::on_ModelList_clicked(const QModelIndex &index)
  7. {
  8. //cleaning
  9. ui->System_list->setModel(emptymodal);
  10. varsystem="";
  11. tablename="";
  12. bitrate="";
  13.  
  14. QString var2=ui->ModelList->model()->data(index).toString();
  15. varmodel=ui->ModelList->model()->data(index).toString();
  16. connOpen();
  17. QSqlQuery* query=new QSqlQuery(mydb);
  18.  
  19. query->prepare("SELECT year FROM maker_data WHERE manufacturer='"+varmnf+"' AND model='"+var2+"'");
  20. query->exec();
  21. modal->setQuery(*query);
  22. ui->YearList->setModel(modal);
  23. connClose();
  24.  
  25. qDebug() <<(query->lastQuery());
  26.  
  27. }
  28. void MainWindow::on_mnfList_clicked(const QModelIndex &index){codehere}
  29. void MainWindow::on_YearList_clicked(const QModelIndex &index){codehere}
To copy to clipboard, switch view to plain text mode 

Basically what It do is update on click the index and send to my variables (mnfvar [manufacturer] -> modelvar[model] -> yearvar [fabrication year] -> systemvar [type os system] ) With those variables with the correct values from SQL, I can call the function above (that's another query) to get tablename. The problem comes when I call it from simulationTask.cpp, and it doesnt have those variables, I tried returning tablename in function but it's not working.

Also tried with get and set methods and not working, I tried a dirty way too, I make a LineTextEdit in 1st window UI, where I sent my tablename record, well, when loading from 2nd window UI it also loads the INITIALIZED value "test" (and not the actual one being showed "gpunto")... I think it's something bad with headers or ui initialization because it's not normal.