Skip to content

GType registration order issue #1517

Description

@Daniel15

Version: 0.8.0-preview1

I have a PressAndHoldButton.cs that subclasses Button. It does not use a template:

/// <summary>
/// A button that emits events while it is being held in.
/// </summary>
[GObject.Subclass<Button>(qualifiedName: nameof(PressAndHoldButton))]
public partial class PressAndHoldButton
{
	....
}

I have a PanAndTiltButtons.blp Blueprint file that uses this component:

using Gtk 4.0;

template $PanAndTiltButtons : Grid {
  column-spacing: 4;
  row-spacing: 4;

  $PressAndHoldButton _up {
    tooltip-text: _('Up');
    icon-name: 'go-up';
    width-request: 50;
    height-request: 50;

    layout {
      row: '0';
      column: '1';
    }
  }
...

This compiles to PanAndTiltButtons.ui:

<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="PanAndTiltButtons" parent="GtkGrid">
    <property name="column-spacing">4</property>
    <property name="row-spacing">4</property>
    <child>
      <object class="PressAndHoldButton" id="_up">
        <property name="tooltip-text" translatable="yes">Up</property>
        <property name="icon-name">go-up</property>
        <property name="width-request">50</property>
        <property name="height-request">50</property>
        <layout>
          <property name="row">0</property>
          <property name="column">1</property>
        </layout>
      </object>
    </child>
    .....

which is used in PanAndTiltButtons.cs:

/// <summary>
/// Renders up, down, left, and right buttons to adjust the pan and tilt.
/// </summary>
[GObject.Subclass<Grid>(qualifiedName: nameof(PanAndTiltButtons))]
[Template<EntryAssemblyResource>("PanAndTiltButtons.ui")]
public partial class PanAndTiltButtons
{
	[Connect] private PressAndHoldButton _up;
	...
}

When I run the app, I get this error:

(webcamcontrol:44449): Gtk-CRITICAL **: 14:33:47.628: Error building template class 'PanAndTiltButtons' for an instance of type 'PanAndTiltButtons': .:0:0 Invalid object type 'PressAndHoldButton'

because the PressAndHoldButton GType isn't registered yet at the time the PanAndTiltButtons instance is created. Manually calling PressAndHoldButton.GetGType() before creating the PanAndTiltButtons instance works, which is the workaround I'm using for now.

Is this something that Gir.Core could handle itself? Automatically register subclasses on app init rather than lazily when GetGType is called?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions