Skip to content

Fix HamLib radio type and Enable checkbox reset on settings open#1002

Merged
ea4k merged 3 commits into
ea4k:masterfrom
barjac:bcj-hamlib-setting-radio
May 14, 2026
Merged

Fix HamLib radio type and Enable checkbox reset on settings open#1002
ea4k merged 3 commits into
ea4k:masterfrom
barjac:bcj-hamlib-setting-radio

Conversation

@barjac

@barjac barjac commented May 12, 2026

Copy link
Copy Markdown

Summary

Two related bugs in the HamLib settings page that cause the saved radio type and the "Enable HamLib" checkbox state to be silently overwritten whenever the user opens the Settings dialog and clicks OK without visiting the HamLib tab.


Bug 1: Radio type overwritten with first list entry

What happens

After opening Settings → OK (without visiting the HamLib tab), the saved radio type (e.g. NET rigctl) is replaced with whichever rig appears first in the alphabetically-sorted list.

Root cause

SetupPageHamLib lazy-loads the rig combo box — it is only populated in showEvent() the first time the HamLib tab is shown. However, saveSettings() is called unconditionally on every OK click, and writes:

```cpp
settings.setValue("HamLibRigType",
hamlib->getModelIdFromName(rigTypeComboBox->currentText()));
```

When the combo is empty, currentText() is "". getModelIdFromName("") uses QMap::operator[] on a missing key, which default-constructs to 0. So HamLibRigType=0 is written to config, overwriting the correct saved value.

On the next run, setRigType("0") looks up model ID 0, finds nothing (hamlib models start at 1), and falls back to setCurrentIndex(0) — the first rig alphabetically.

When it was introduced

The showEvent() lazy-load guard (m_rigsLoaded) was added to defer the expensive rig_load_all_backends() call until the HamLib tab is actually visited. This created the window where saveSettings() could be called before the combo was ever populated.

Fix

Guard the HamLibRigType write with m_rigsLoaded. If the combo was never populated this session, the existing config value is left untouched:

```cpp
if (m_rigsLoaded)
settings.setValue("HamLibRigType", ...);
```

Trigger conditions

  • Most commonly: first run after a new version install, where checkIfNewVersion() forces the Settings dialog open and the user clicks OK after updating their callsign without visiting the HamLib tab.
  • Also: any Settings open → OK without visiting the HamLib tab.

Bug 2: "Enable HamLib" checkbox shown unchecked/disabled

What happens

Opening the Settings → HamLib tab shows the "Enable HamLib" checkbox as unchecked and grayed out, even when HamLib was previously configured and enabled.

Root cause

Two issues working together:

a) setRigType() in loadSettings() calls setCurrentIndex() on the combo, which fires currentTextChangedslotRadioComboBoxChanged()setTestResult(false). setTestResult(false) unchecks and disables the activation checkbox — before loadSettings() has had a chance to restore it from config.

b) setDefaults() (called from the constructor) calls setTestResult(false), which disables the checkbox. loadSettings() calls setChecked() to restore the saved value, but never calls setEnabled(), so the checkbox remains disabled even when HamLibActive=true.

When it was introduced

The showEvent() lazy-load commit moved rig-list population out of createUI() and into showEvent(). Before that change, the combo was populated at construction time, and by the time loadSettings() was called the signal chain was less disruptive. The lazy-load commit exposed both issues simultaneously.

Fix

Two targeted changes to loadSettings():

```cpp
// Block signals so setRigType() cannot trigger setTestResult(false)
rigTypeComboBox->blockSignals(true);
setRigType(settings.value("HamLibRigType").toString());
rigTypeComboBox->blockSignals(false);

// Re-enable the checkbox if it was previously active
const bool wasActive = settings.value("HamLibActive", false).toBool();
activateHamlibCheckBox->setChecked(wasActive);
if (wasActive)
activateHamlibCheckBox->setEnabled(true);
```


Testing

  • Confirmed with NET rigctl (model saved as non-zero ID).
  • Open Settings, change something on any tab other than HamLib, click OK → rig type preserved.
  • Open Settings, navigate to HamLib tab → "Enable HamLib" checkbox shown checked and enabled.
  • Fresh install (no config) → checkbox correctly starts unchecked/disabled.

🤖 Generated with Claude Code

Barry Jackson and others added 3 commits May 11, 2026 21:39
…sion install

saveSettings() was writing HamLibRigType=0 whenever the HamLib tab had never
been shown (combo unpopulated). rigTypeComboBox->currentText() returns "" on an
empty combo, and getModelIdFromName("") uses QMap::operator[] on a missing key,
which default-constructs to 0. On next run setRigType("0") falls back to
setCurrentIndex(0), silently selecting the first rig alphabetically.

Guard the HamLibRigType write with m_rigsLoaded so the saved value is only
updated when the combo has actually been populated.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two related regressions introduced by the lazy-load showEvent() commit:

1. setRigType() in loadSettings() fired currentTextChanged which called
   slotRadioComboBoxChanged() -> setTestResult(false), unchecking and
   disabling the activation checkbox before loadSettings() could restore it.
   Fix: blockSignals around setRigType() in loadSettings().

2. setDefaults() (constructor) disables the checkbox via setTestResult(false),
   but loadSettings() only called setChecked() — not setEnabled() — leaving
   the checkbox checked-but-grayed-out even when HamLibActive=true.
   Fix: re-enable the checkbox in loadSettings() when HamLibActive was true.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ea4k ea4k merged commit 8c568cd into ea4k:master May 14, 2026
2 of 8 checks passed
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants