Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Positioning and NMEA

Qt Positioning and NMEA

Scheduled Pinned Locked Moved Solved General and Desktop
positioningpositionsourceqtpositioninggps
2 Posts 1 Posters 396 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dpaulat
    wrote on 6 May 2024, 02:41 last edited by dpaulat 5 Jun 2024, 02:42
    #1

    I'm trying to follow along with the NMEA guide, and am having some trouble (Qt 6.7.0, MSVC 2022, Windows 11): https://doc.qt.io/qt-6/position-plugin-nmea.html

    I have the Qt Positioning module installed, and can create a default GeoPositionInfoSource, but not an NMEA source. I'm instead getting a null pointer when calling the createSource function from the example. I've attached a minimal example.

    CMakeLists.txt:

    cmake_minimum_required(VERSION 3.14)
    
    project(qt-nmea-test LANGUAGES CXX)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Positioning)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Positioning)
    
    add_executable(qt-nmea-test
      main.cpp
    )
    target_link_libraries(qt-nmea-test Qt${QT_VERSION_MAJOR}::Core
                                       Qt${QT_VERSION_MAJOR}::Positioning)
    
    include(GNUInstallDirs)
    install(TARGETS qt-nmea-test
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    

    main.cpp:

    #include <QGeoPositionInfoSource>
    #include <QVariantMap>
    
    int main(int argc, char *argv[])
    {
        qDebug() << "Available sources: " << QGeoPositionInfoSource::availableSources();
    
        QGeoPositionInfoSource *defaultSource = QGeoPositionInfoSource::createDefaultSource(nullptr);
        if (defaultSource != nullptr)
            qDebug() << "Default source is good!";
        else
            qDebug() << "Default source is null";
    
        QVariantMap params;
        params["nmea.source"] = "socket://localhost:22222";
        QGeoPositionInfoSource *nmeaSource = QGeoPositionInfoSource::createSource("nmea", params, nullptr);
        if (nmeaSource != nullptr)
            qDebug() << "NMEA source is good!";
        else
            qDebug() << "NMEA source is null";
    }
    

    I get the following output:

    Available sources:  QList("nmea", "winrt")
    Default source is good!
    NMEA source is null
    

    I've traced it to https://github.com/qt/qtpositioning/blob/v6.7.0/src/positioning/qgeopositioninfosource.cpp#L83. It's attempting to load the factory class, but the factory instance returned on this line is null.

    I have similar results on Qt 6.6.2, using both MSVC 2022 and GCC 11 (Ubuntu 22.04).

    Am I missing some initialization step? Am I using the plugin incorrectly?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dpaulat
      wrote on 12 May 2024, 15:02 last edited by
      #2

      The NMEA plugin also requires the Qt Serial Port plugin. After installing it, the same snippet of code works as expected.

      1 Reply Last reply
      1
      • D dpaulat has marked this topic as solved on 12 May 2024, 15:03

      1/2

      6 May 2024, 02:41

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved