Retrieve Location Using Qt Mobility/bg: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Convert ExpressionEngine section headers)
(Sub-categorize)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
 
{{LangSwitch}}
[[Category:Developing with Qt::QtMobility]]
[[Category:Developing with Qt::QtMobility]]
[[Category:HowTo]]
[[Category:HowTo]]
[[Category:Snippets]]
[[Category:Snippets::Misc]]
[[Category:Tutorial]]
[[Category:Tutorial]]
 
[[Category:Bulgarian]]
[toc align_right="yes" depth="4"]
 
'''Български''' [[Retrieve_Location_Using_Qt_Mobility|English]]


= Намиране на местоположение с Qt Mobility =
= Намиране на местоположение с Qt Mobility =
Line 42: Line 39:
#define MAINWINDOW_H
#define MAINWINDOW_H


#include <QtGui/QMainWindow>
#include <QMainWindow>
#include <QGeoPositionInfo>
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
#include <QGeoPositionInfoSource>
Line 98: Line 95:
#include <QDesktopWidget>
#include <QDesktopWidget>


#include <QtCore/QCoreApplication>
#include <QCoreApplication>


#include <QDebug>
#include <QDebug>
Line 144: Line 141:
  qreal longitude = geoCoordinate.longitude();
  qreal longitude = geoCoordinate.longitude();


  m_pLabel->setText( QString("Latitude: %1 Longitude: %2[http://bugreports.qt.nokia.com/browse/QTMOBILITY-1550?focusedCommentId=151456&amp;amp;page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel ).arg(latitude).arg(longitude) );
  m_pLabel->setText( QString("Latitude: %1 Longitude: %2[http://bugreports.qt.nokia.com/browse/QTMOBILITY-1550?focusedCommentId=151456&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel ).arg(latitude).arg(longitude) );
  }
  }
}
}

Latest revision as of 12:10, 28 November 2016

This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine.
Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean.

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

Намиране на местоположение с Qt Mobility

Общ преглед

Предоставеният програмен код показва как се намира местоположението чрез клас QGeoPositionInfoSource от Qt Mobility. След като бъде установена позицията на екрана се показват нейните координати (географска ширина и дължина). Примерът е тестван на Nokia E7 със Symbian^3

Следните методи за позициониране могат да бъдат използвани:

  • SatellitePositioningMethods - Сателитни методи за позициониране като GPS.
  • NonSatellitePositioningMethods - Други позициониращи методи.
  • AllPositioningMethods- Всички позициониращи methods.

Примерната програма използва NonSatellitePositioningMethods.

Програмен код

Проектен файл

Qt Mobility трябва да бъде включено в проектовия файл (.pro). Освен това, ако програмата е за устройства със Symbian трябва да бъде добавена възможността Location.

symbian:TARGET.CAPABILITY ''= NetworkServices Location

CONFIG''= mobility
MOBILITY += location

Хедър

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>
#include <QLabel>

// QtMobility namespace
QTM_USE_NAMESPACE

namespace Ui {
 class MainWindow;
}

class MainWindow : public QMainWindow
{
 Q_OBJECT
public:

explicit MainWindow(QWidget '''parent = 0);

 virtual ~MainWindow();

public slots:
 /'''*
 * Called when the current position is updated.
 *
 *

return nothing

*/
void positionUpdated(QGeoPositionInfo geoPositionInfo);

private:

/*
* Start listening for position changes
*

*

return nothing
 */
 void startLocationAPI();

private:
 QGeoPositionInfoSource''' m_pLocationInfo;

QLabel* m_pLabel;

};

#endif // MAINWINDOW_H

Код

#include "mainwindow.h"

#include <QGeoCoordinate>
#include <QApplication>
#include <QDesktopWidget>

#include <QCoreApplication>

#include <QDebug>

MainWindow::MainWindow(QWidget '''parent)
 : QMainWindow(parent), m_pLocationInfo(NULL), m_pLabel(NULL)
{
 m_pLabel = new QLabel("",this);
 m_pLabel->setGeometry(QApplication::desktop()->screenGeometry());
 startLocationAPI();
}

MainWindow::~MainWindow()
{

}

void MainWindow::startLocationAPI()
{
 // Obtain the location data source if it is not obtained already
 if (!m_pLocationInfo)
 {
 m_pLocationInfo =
 QGeoPositionInfoSource::createDefaultSource(this);

 //Select positioning method
 m_pLocationInfo->setPreferredPositioningMethods(QGeoPositionInfoSource::NonSatellitePositioningMethods);

 // When the position is changed the positionUpdated function is called
 connect(m_pLocationInfo, SIGNAL (positionUpdated(QGeoPositionInfo)),
 this, SLOT (positionUpdated(QGeoPositionInfo)));

 // Start listening for position updates
 m_pLocationInfo->startUpdates();
 }
}

void MainWindow::positionUpdated(QGeoPositionInfo geoPositionInfo)
{
 if (geoPositionInfo.isValid())
 {
 // Get the current location coordinates
 QGeoCoordinate geoCoordinate = geoPositionInfo.coordinate();
 qreal latitude = geoCoordinate.latitude();
 qreal longitude = geoCoordinate.longitude();

 m_pLabel->setText( QString("Latitude: %1 Longitude: %2[http://bugreports.qt.nokia.com/browse/QTMOBILITY-1550?focusedCommentId=151456&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel ).arg(latitude).arg(longitude) );
 }
}

Отстраняване на проблеми

'QGeoPositionInfo' has not been declared

Всички нужни хедър файлово трябва да бъдат включени и да бъде оказан namespace Qt Mobility.

#include <QGeoPositionInfo>
#include <QGeoPositionInfoSource>

// QtMobility namespace
QTM_USE_NAMESPACE
  • AllPositioningMethods не работи според очакванията

Това е известен критичен бъг, който засяга Qt Mobility 1.1.2]. Моля вижте посочената страница за повече информация.

Вижте също