setBackgroundImage: _QObject_InvokeMethod failed

Hey

I’m using the following code, adapted from the View help file, to try to set a background image:

(
~bounds = Rect(10, 10, 150, 18);
~image = Image.new("/home/badnumbers/Documents/Swamp.png");
~window = Window.new("Image background");
~slider = Slider.new(~window, ~bounds);
~slider.setBackgroundImage(~image);
~window.front;
~image.free;
)

This code results in ERROR: Primitive '_QObject_InvokeMethod' failed., thrown by Slider I think.

Using backgroundImage_ results in the same error.

The file does exist at that location! (I have tried various locations to rule out file permissions issues.)

I’m running Kubuntu 2024.10.

Can anyone help?

Away from my computer, but about 99% sure it’s because you can’t set backgroundImage of class Slider. You could with a Window or View.

@mjsyts is correct.

You can fix it by doing so (and removing ~image.free; which would cause the image to disappear):

(
~bounds = Rect(10, 10, 150, 18);
~image = Image.new(SCDoc.helpSourceDir +/+ "images/Swamp.png");
~window = Window.new("Image background");
~sliderView = UserView.new(~window);
~sliderView.setBackgroundImage(~image);
~slider = Slider.new(~sliderView, ~bounds);
~window.front;
)

Here’s an improvement proposition:

(
var image = Image(SCDoc.helpSourceDir +/+ "images/Swamp.png");
var sliderView = UserView().setBackgroundImage(image, 16);

~window = Window("Image background");
~slider = Slider().maxWidth_(64);

sliderView.layout_(
	HLayout()
	.add(~slider)
);
~window.layout_(
	VLayout()
	.add(sliderView)
);
~window.front;

// When window is closed, image is freed
~window.onClose_({
	image.free;
});
)

Thank you for your replies. Unfortunately this doesn’t appear to be a Slider-specific issue. I think this may be platform specific.

When I run @Dindoleon’s example code I get:

^^ The preceding error dump is for ERROR: Primitive '_QObject_InvokeMethod' failed.
Failed.
RECEIVER: an UserView

Interesting. I though this code would be stable regardless of the platform.

Which OS are you using? Looks like a Debian based distro. Is it on a raspberry?

Also, can you check the image file actually exists at the specified location?

Here is the simplest code I have to reproduce the issue:

(
var win = Window("TEST", Rect(50,50,500,500));
var image = Image.new(SCDoc.helpSourceDir +/+ "images/Swamp.png");
var view = View(win, Rect(50,50,400,400));
view.setBackgroundImage(image);
win.front;
)

It gives me:

^^ The preceding error dump is for ERROR: Primitive '_QObject_InvokeMethod' failed.
Failed.
RECEIVER: a View

I’m using Kubuntu 24.10 on a Lenovo laptop.

SCDoc.helpSourceDir +/+ "images/Swamp.png" gives me /usr/local/share/SuperCollider/HelpSource/images/Swamp.png, which does exist and can be opened by the OS. I’ve also tried copying it to ~/Documents and pointing Image to there, but the result is the same.

EDIT: it also fails with flowers2.jpg in the same folder.

Oh sorry didn’t see you specified your OS in the initial post.

I fear I might not be able to help you with this. The code is running fine on my computer, using Ubuntu 22.04, QT6 and SuperCollider 3.14.0-dev.

The only reason I can think of is that somehow your SuperCollider version and your Qt version are not matching. But that seems silly, I think a lot of other things would break.

Or maybe is it just a permission issue, the file cannot be read, so the Image isn’t created?

Is this at least working:

Image.new(SCDoc.helpSourceDir +/+ "images/Swamp.png").plot

?

No worries, I appreciate your time.

Yes, the plot does work.