Hi!

I'm very new at Qt and c++ programming, and I created a Qt GUI and have some global variables that I change when my callbacks are called.
I would like to print those global variables in my terminal, so I wrote in my main.cpp the following:

Qt Code:
  1. #include "ros/ros.h"
  2.  
  3. #include "mainwindow.h"
  4. #include <QApplication>
  5. #include "globals.h"
  6. #include "qtgui/GUIDados.h"
  7.  
  8. using namespace std;
  9.  
  10. namespace global2
  11. {
  12. int numberOfMotors;
  13. int intensidade[16];
  14. int local[16];
  15. }
  16.  
  17. int main(int argc, char *argv[])
  18. {
  19.  
  20. QApplication a(argc, argv); //creates a QApplication object
  21. MainWindow w; //creates the main window object
  22. w.show();
  23.  
  24. cout << "test: " << global2::numberOfMotors << endl;
  25. return a.exec(); //enter its event loop
  26.  
  27. }
To copy to clipboard, switch view to plain text mode 

However, I always get test 0 and nothing else. In my mainwindow.cpp I am able to write those global variables in a label in my gui, like for example:
(this is just an excerpt of my mainwindow.cpp code)

Qt Code:
  1. #include "ros/ros.h"
  2.  
  3. #include "mainwindow.h"
  4. #include "ui_mainwindow.h"
  5. #include <QtGui/QPushButton>
  6. #include "globals.h"
  7. #include <QString>
  8. #include <string>
  9. #include <sstream>
  10. #include "QMessageBox"
  11.  
  12.  
  13. namespace global
  14. {
  15. int numberOfMotors;
  16. int intensidade[16];
  17. int local[16];
  18. }
  19.  
  20. using namespace std;
  21.  
  22. void MainWindow::on_sendButton_clicked()
  23. {
  24. QMessageBox::information(this,tr("Titulo"),tr("escolheu: %1").arg( global::intensidade[0]));
  25. ui->label1->setText(QString::number(global::numberOfMotors));
  26. }
To copy to clipboard, switch view to plain text mode 

Can you explain me what I'm doing wrong?