Skip to content

QtCollider: fix Q_INVOKABLE SharedImage typename#6970

Merged
elgiano merged 1 commit intosupercollider:3.14from
elgiano:topic/fix-qt-invokable-sharedimage
Jun 11, 2025
Merged

QtCollider: fix Q_INVOKABLE SharedImage typename#6970
elgiano merged 1 commit intosupercollider:3.14from
elgiano:topic/fix-qt-invokable-sharedimage

Conversation

@elgiano
Copy link
Contributor

@elgiano elgiano commented Jun 11, 2025

Purpose and Motivation

Fixes #6936

We had this problem before with TreeView, see #6521. This PR applies the same fix.

SharedImage is a typedef for QSharedPointer<QtCollider::Image>. Qt registers it as a MetaType with its full name QSharedPointer<QtCollider::Image>, so Q_INVOKABLE methods needs to use the same name, otherwise method calls fail with QMetaMethod::invoke: cannot convert formal parameter 0 from QSharedPointer<QtCollider::Image> to SharedImage.. Even if the type is the same, Qt gets confused about its name.

Here is a note from Qt docs:

Note: Do not use typedef or using for Q_PROPERTY types as these will confuse moc. This may make certain type comparisons fail.

For any other use than Q_INVOKABLE, SharedImage should be fine, so we can keep the typedef.
I decided to patch also when used with Q_PROPERTY, since Qt mentions it explicitly, even though those methods didn't fail.

You can use this code to test affected Widgets:

var image = Image("PATH/TO/YOUR/IMAGE");
View(bounds:300@300).layout_(VLayout(
	View().setBackgroundImage(image),
	Button().icon_(image),
	Menu(MenuAction("test").icon_(image))
)).front

Types of changes

  • Bug fix

To-do list

  • Code is tested
  • All tests are passing
  • This PR is ready for review

Qt registers SharedImage as a MetaType with its full name
(QSharedPointer<QtCollider::Image>), so Q_INVOKABLE methods needs to use the
same, otherwise method calls fail with `QMetaMethod::invoke: cannot convert
formal parameter 0 from QSharedPointer<> to SharedImage.`
@elgiano elgiano force-pushed the topic/fix-qt-invokable-sharedimage branch from 1667af0 to 99ed37d Compare June 11, 2025 10:43
Copy link
Contributor

@capital-G capital-G left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - wanted to take a look at this today but glad that this has been fixed now :)

Just wanted to know - how did you got the error message QMetaMethod::invoke: cannot convert formal parameter 0 from QSharedPointer<QtCollider::Image> to SharedImage.? This would have helped me a lot during first inspection?

@capital-G capital-G added comp: Qt GUI sclang Qt components -- for IDE tickets, use "env: SCIDE" instead qt6 issues specific to version 6 of Qt labels Jun 11, 2025
@capital-G capital-G added this to 3.14.0 Jun 11, 2025
@capital-G capital-G moved this to URGENT in 3.14.0 Jun 11, 2025
@elgiano
Copy link
Contributor Author

elgiano commented Jun 11, 2025

@capital-G I run sclang in a terminal. IIUC we don't get Qt errors in scide post window because they go to stderr.

@elgiano elgiano merged commit e8a06ee into supercollider:3.14 Jun 11, 2025
24 checks passed
@github-project-automation github-project-automation bot moved this from URGENT to Done in 3.14.0 Jun 11, 2025
@elgiano elgiano deleted the topic/fix-qt-invokable-sharedimage branch June 11, 2025 12:56
dyfer pushed a commit to dyfer/supercollider that referenced this pull request Jul 16, 2025
Qt registers SharedImage as a MetaType with its full name
(QSharedPointer<QtCollider::Image>), so Q_INVOKABLE methods needs to use the
same, otherwise method calls fail with `QMetaMethod::invoke: cannot convert
formal parameter 0 from QSharedPointer<> to SharedImage.`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: Qt GUI sclang Qt components -- for IDE tickets, use "env: SCIDE" instead qt6 issues specific to version 6 of Qt

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants