Skip to content

CDockWidgetTab created in CDockWidget constructor causes issue with python bindings #847

Description

@pylessard

This issue is related to this: mborgerson/pyside6_qtads#116
The problem reported here is not specifically with this repo, but a combination of the public API this repo exposes and how PySide6 (Python's bindings) behave.

In the CDockWidget constructor, a CDockComponentsFactory::createDockWidgetTab is invoked to create a tab.
This causes an issue because the factory can be given by Python, but PySide6 creates the wrapper for an object after the constructor is executed (as far as I understand). There is an init order issue where the wrapper to the python tab widget is tied to a wrapper that has not yet been registered into the PySide6 layer.

I believe the CDockWidgetTab object should be created outside the CDockWidget constructor. This would apply to any class that can be extended in Python through a custom Factory : CDockWidgetTab, CDockAreaTitleBar, CDockAreaTabBar, CAutoHideTab. Right now, it looks like only the CDockWidgetTab class violates this requirement causing troubles to the Python level. If we look at the issues raised on pyside6_qtads, we see that PySide instantiates more than one wrapper for the same underlying CDockWidget.

I would propose a lazy instantiation of the CDockWidgetTab object. Something like this

CDockWidgetTab* CDockWidget::tabWidget() const {
	if (!d->TabWidget) {
		d->TabWidget = d->componentsFactory()->createDockWidgetTab(this);
	}
	return d->TabWidget;
}

And then access the TabWidget internally through tabWidget().
I tested locally and the problem seems to disappear; PySide6 creates a single wrapper object.

For some reason I can't explain (yet), the problem appeared between PySide6.9 and PySide6.11, on Windows only.

I will open a PR with a fix proposal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions