I am looking for a solution to connect a GPS-device on a COM-Port in QGIS 3 using Python. The GPS is working in the QGIS 3 GPS Gui as it should. As there are many changes between QGIS 2 and 3 the examples of accessing a GPS device with Python in QGIS 2 ( Connect / Disconnect GPS device via PyQGIS ) are not working for QGIS 3 anymore.

Examples of working code using the different GPS-classes form QGIS 3 are not available.


from qgis.core import *

results in a list of the available ports like:

[('internalGPS', 'Interes GPS'), ('localhost:2947:', 'Lokaler GPSD'), ('COM1', 'COM1: Kommunikationsanschluss'), ('COM6', 'COM6: Standardmäßgige Seriell-über-Bluetooth-Verbindung'), ('COM5', 'COM5: Standardmäßgige Seriell-über-Bluetooth-Verbindung'), ('COM4', 'COM4: ')]

By looking at the API at https://qgis.org/pyqgis/3.0/core/Gps/QgsGpsConnection.html the QgsGpsConnection should be the way to go. In QGIS 3 it is not possible to use a string for the port using QgsGpsConnection. It has to be QIODevice. So I tried using

from qgis.core import *
from PyQt5.QtSerialPort import QSerialPort
port = QSerialPort("COM5")

At this point I am stuck. I used several ways of QgsGpsConnection() like


con = QgsGpsConnection(port)

but I always recieve an TypeError: qgis._core.QgsGpsConnection represents a C++ abstract class and cannot be instantiated .

As I am new to Python in QGIS I do not know how to go on. My goal is to access the XY-Position and the accuracy of the signal.

  • The examples of accessing a GPS device with QGIS 3 are not working because names of classes have changed. I will vote for reopening this question. You also can edit your question to fit the rules in the help center and one Administrator reopen it. – xunilk Dec 30 '18 at 16:51
  • Just edited the question after some more try and error. Hopefully someone can provide some help. – Firefly Dec 30 '18 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.