Settings loading after PositionSource instantiated, wrong PluginParameter value passed
-
I am trying to add a baud rate setting to my QML app so that the baud rate can be changed when connecting to a NMEA GPS PositionSource. I've modified the serialnmea plugin code to accept
serialnmea.baud_rate
as a parameter and set the serial port baud rate appropriately. Everything works as expected when I hard code the value of theserialnmea.baud_rate
PluginParameter, but when I try to set it using an ApplicationWindow property that is aliased within Settings, it doesn't use the value from Settings. It is as though the code activates the serialnmea plugin before retrieving my baud rate setting.I'm using Qt 5.14.2 with the serialnmea code patched to fix a bug that was corrected in 5.15.0. My code looks like this (heavily snipped):
import QtPositioning 5.14 import Qt.labs.settings 1.1 as AppSettings ApplicationWindow { id: appWindow property int baudRate: 4800 AppSettings.Settings { property alias baudRate: appWindow.baudRate Component.onCompleted: { console.log(`appSettings completed, baudRate = ${baudRate}`); } } PositionSource { id: positionSource name: "serialnmea" PluginParameter { name: "serialnmea.baud_rate" value: baudRate ? baudRate : 4800 } ... } }
When I run the program, the Application Output window shows the serial nmea logging output first, and a detected
serialnmea.baud_rate
parameter of 4800 being passed in (becausebaudRate
is apparently zero at that point in the code execution and the ternery operator resolves to 4800). Later in the output, I seeappSettings completed, baudRate = 2400
, reflecting the value I've placed into settings on a previous run.Is there a way to delay the initiation of the PositionSource/serialnmea plugin until all the settings have been loaded?
Or, is there a way to re-load the PositionSource once the program has started? As it is now, when a user changes the serial port (another parameter I'm passing to serialnmea), they have to restart the program in order to use the new port.