title: how to access variable from one class in another in QT mobility?
body: <p>I have two classes: first generate position data (latitude and longitude), how I can access this data (variables latitude and longitute) in second class? becouse in second class I get crazy number(</p>
  
  <p>Here are headers and classes:
  <strong>first header:</strong></p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;QGeoPositionInfoSource&gt;
  #include &lt;QGeoPositionInfo&gt;
  #include &lt;QtCore/QPointer&gt;
  #include &lt;QGeoSatelliteInfo&gt;
  #include &lt;QGeoSatelliteInfoSource&gt;
  #include "gpsform.h"
  QTM_USE_NAMESPACE
  
  namespace Ui {
      class MainWindow;
  }
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();
      double latitude;
      double longitude;
      double altitude;
      double speed;
  
  public slots:
      void positionUpdated(QGeoPositionInfo geoPositionInfo);
  
  private:
      Ui::MainWindow *ui;    
      QPointer&lt;QGeoPositionInfoSource&gt; locationDataSource;
  
  private slots:
      void on_pushButton_2_clicked();
      void on_pushButton_4_clicked();
      void startGPS();
      void on_pushButton_clicked();
  
  signals:
      void updated();
  };
  
  #endif // MAINWINDOW_H
  </code></pre>
  
  <p><strong>first class</strong></p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  #include "quitdiallog.h"
  #include &lt;QGeoCoordinate&gt;
  #include &lt;QDebug&gt;
  #include &lt;QtGui/QMessageBox&gt;
  #include &lt;QList&gt;
  #include "gpsform.h"
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      setWindowTitle("Мой кОмпаС");
      ui-&gt;setupUi(this);
      startGPS();
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  void MainWindow::startGPS()
  {
      // Obtain the location data source if it is not obtained already
      if (!locationDataSource)
      {
          locationDataSource =
                  QGeoPositionInfoSource::createDefaultSource(this);
          if (locationDataSource)
          {
              // Whenever the location data source signals that the current
              // position is updated, the positionUpdated function is called.
              QObject::connect(locationDataSource,
                               SIGNAL(positionUpdated(QGeoPositionInfo)),
                               this,
                               SLOT(positionUpdated(QGeoPositionInfo)));
              // Start listening for position updates
                      locationDataSource-&gt;setUpdateInterval(100);
                      locationDataSource-&gt;setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods);
              locationDataSource-&gt;startUpdates();
          } else {
              // Not able to obtain the location data source
              // TODO: Error handling
          }
      } else {
          // Start listening for position updates
          locationDataSource-&gt;setUpdateInterval(5000);
          locationDataSource-&gt;startUpdates();
      }
  }
  
  void MainWindow::positionUpdated(QGeoPositionInfo geoPositionInfo)
  {
      //gpsform *gpf=new gpsform;
      if (geoPositionInfo.isValid())
      {
          //locationDataSource-&gt;stopUpdates();
          QGeoCoordinate geoCoordinate = geoPositionInfo.coordinate();
          latitude = geoCoordinate.latitude();
          longitude = geoCoordinate.longitude();
          altitude=geoCoordinate.altitude();
      ui-&gt;label-&gt;setNum(latitude);
      ui-&gt;label_2-&gt;setNum(longitude);
      /*if(QGeoPositionInfo::GroundSpeed)
      {
          speed=QGeoPositionInfo::GroundSpeed;
      ui-&gt;label_4-&gt;setNum(speed);
      }*/
      emit updated();
      //gpf-&gt;latitude=this-&gt;latitude;
      //gpsform *gpf=new gpsform;
      //gpf-&gt;show();
      //gpf-&gt;latitude=latitude;
      }
  }
  
  
  
  void MainWindow::on_pushButton_clicked()
  {    
      /*ui-&gt;label_3-&gt;setNum(latitude);
      qDebug()&lt;&lt;latitude&lt;&lt;"    "&lt;&lt;longitude&lt;&lt;"   "&lt;&lt;altitude;*/
      gpsform *gps=new gpsform;
      this-&gt;hide();
      gps-&gt;show();
  
  }
  
  void MainWindow::on_pushButton_4_clicked()
  {
      QuitDiallog *qi=new QuitDiallog;
      this-&gt;hide();
      qi-&gt;show();
  }
  
  void MainWindow::on_pushButton_2_clicked()
  {
      ui-&gt;label_3-&gt;setNum(latitude);
  }
  </code></pre>
  
  <p><strong>second header</strong></p>
  
  <pre><code>#ifndef GPSFORM_H
  #define GPSFORM_H
  
  #include &lt;QWidget&gt;
  #include "mainwindow.h"
  QTM_USE_NAMESPACE
  namespace Ui {
      class gpsform;
  }
  
  class gpsform : public QWidget
  {
      Q_OBJECT
  
  public:
      explicit gpsform(QWidget *parent = 0);
      ~gpsform();
      double latitude;
  
  private:
      Ui::gpsform *ui;    
  
  private slots:    
      void on_pushButton_clicked();
      void updatedata();
  };
  
  #endif // GPSFORM_H
  </code></pre>
  
  <p><strong>second class:</strong></p>
  
  <pre><code>#include "gpsform.h"
  #include "ui_gpsform.h"
  #include "mainwindow.h"
  #include &lt;QTimer&gt;
  #include &lt;QDebug&gt;
  
  gpsform::gpsform(QWidget *parent) :
      QWidget(parent),
      ui(new Ui::gpsform)
  {
      ui-&gt;setupUi(this);
      /*ui-&gt;label-&gt;setNum(mw-&gt;latitude);*/
     /* QTimer * timer = new QTimer(this);
      connect(timer,SIGNAL(timeout()),this,SLOT(update()));
      timer-&gt;start(50);*/
     /* MainWindow *mw = new MainWindow;
      QObject::connect(mw,SIGNAL(updated()),this,SLOT(updatedata()));*/
  }
  
  gpsform::~gpsform()
  {
      delete ui;
  }
  
  void gpsform::updatedata()
  {
     /* MainWindow *mw = new MainWindow;
      this-&gt;latitude=mw-&gt;latitude;
      ui-&gt;label-&gt;setNum(mw-&gt;latitude);*/
  }
  
  void gpsform::on_pushButton_clicked()
  {
          MainWindow *mw = new MainWindow;
          //latitude=mw-&gt;latitude;
          qDebug()&lt;&lt;mw-&gt;latitude;
          ui-&gt;label-&gt;setNum(latitude);
  }
  </code></pre>
  
  <p>For example I want to see latitude in second class, by pressing button. In future I'll do this by Signal/slot to generate label text every time, the position is updated. But now I'll get crazy number. <strong>Help me please</strong></p>