Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 27th, 2012  |  syntax: None  |  size: 1.08 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. MainWindow::MainWindow(QWidget *parent)
  2.     : QMainWindow(parent), ui(new Ui::MainWindow)
  3. {
  4.     ui->setupUi(this);
  5.     location = new LocationWatcher();
  6.     if (location->source)
  7.     {
  8.        connect(location->source, SIGNAL(positionUpdated(QGeoPositionInfo)),
  9.                 this, SLOT(positionUpdated(QGeoPositionInfo)));
  10.  
  11.      //  ui->label->setText( QString("min %1").arg(location->source->minimumUpdateInterval()) );
  12.     }
  13. }
  14.  
  15.  
  16. LocationWatcher::LocationWatcher(QObject *parent)
  17.     : QObject(parent)
  18. {
  19.     source = QGeoPositionInfoSource::createDefaultSource(this);
  20.     enabled = false;
  21.     if (source) {
  22.         source->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);  //QGeoPositionInfoSource::SatellitePositioningMethods
  23.         source->setUpdateInterval(500); // this is the line that gives me trouble, so I just don't use it
  24.    }
  25. }
  26.  
  27. void LocationWatcher::enable()
  28. {
  29.     if (source) {
  30.        source->startUpdates();
  31.         enabled = true;
  32.     }
  33. }
  34.  
  35. void LocationWatcher::disable()
  36. {
  37.     if (source) {
  38.         enabled = false;
  39.         source->stopUpdates();
  40.     }
  41. }