Skip to content

Qt6: Menus randomly fail to display on launch #624

@Cordtus

Description

@Cordtus

Description

When building LazPaint with the Qt6 widgetset (--ws=qt6), menus randomly fail to appear in the main menu bar. The "Image" menu is particularly affected, but other menus can also be missing on any given launch.

Steps to Reproduce

  1. Build LazPaint with Qt6 widgetset: lazbuild --ws=qt6 lazpaint.lpi
  2. Launch the application multiple times
  3. Observe that menus are intermittently missing from the menu bar

Expected Behavior

All menus should appear consistently on every launch.

Actual Behavior

Menus randomly fail to display with roughly 30-70% failure rate across multiple launches. Testing showed only 2/6 launches had the Image menu visible before investigating.

Environment

  • OS: Arch Linux
  • Qt6Pas: 6.2.9
  • FPC: 3.2.2
  • Lazarus: 3.8

Investigation & Root Causes

After debugging, three issues were identified:

1. TActionList.ActionByName Race Condition

ActionByName appears to have timing issues during Qt6 initialization, sometimes returning nil for actions that exist. This causes menu items to silently fail to populate.

2. Missing Visibility Flags

Qt6 sometimes fails to render TMenuItem items even when they're correctly populated. Setting Visible := true explicitly resolves this.

3. Menu Bar Widget Handle Not Refreshed

Qt6's menu bar widget handle needs to be forcibly refreshed after menu population. Without this, the internal Qt widget state doesn't reflect the populated menu structure.

Proposed Fix

A fix has been submitted in PR #623 which:

  1. Replaces ActionByName calls with a direct iteration helper (FindActionByNameDirect) that doesn't rely on hash-based lookup
  2. Adds explicit Visible := true for all active menus
  3. Forces menu bar refresh via detach/reattach with ProcessMessages calls

After the fix, testing achieved 6/6 successful launches (100% success rate).

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions