Discussion:
[PyQt] PyQt5 fails to handle QQuickImageProvider subclassing
Julio César Gázquez
2017-01-04 19:01:58 UTC
Permalink
Hello list. Hi Phil.

I'm dipping my toes on QML. I subclassed QQuickImageProvider in order to
access images stored in a database from the QML side of my app.

Unfortunately, when the QML engine tries to call the provider I'm
getting the following error:

ImageProvider supports Image type but has not implemented requestImage()

Seems this message comes from Qt's QQuickImageProvider::requestImage()
implementation, so it's like the C++ method isn't being overridden by
the PyQt's wrapper method.

At least the alternate QQuickImageProvider::requestPixmap() has the same
problem.

These methods are somewhat peculiar, as they are virtual methods (and
specifically meant to be subclassed) and have an /Out/ parameter. Doing
a grep on the PyQt sources I see this only happens in two places outside
this class. Maybe the wrapper for the virtual method lacks the /Out/
parameter?

BTW, at least another guy was bitten for this:
http://stackoverflow.com/questions/40787663/pyqt5-qquickimageprovider-not-working.

I'm tested it on PyQt5 5.5.1, I'm not sure if it could be fixed in later
versions.

Thanks in advance.

Greetings, Julio.

_______________________________________________
PyQt mailing list ***@riverbankcomputing.com
https://www.ri
Phil Thompson
2017-01-04 19:17:52 UTC
Permalink
Post by Julio César Gázquez
Hello list. Hi Phil.
I'm dipping my toes on QML. I subclassed QQuickImageProvider in order to access images stored in a database from the QML side of my app.
ImageProvider supports Image type but has not implemented requestImage()
Seems this message comes from Qt's QQuickImageProvider::requestImage() implementation, so it's like the C++ method isn't being overridden by the PyQt's wrapper method.
At least the alternate QQuickImageProvider::requestPixmap() has the same problem.
These methods are somewhat peculiar, as they are virtual methods (and specifically meant to be subclassed) and have an /Out/ parameter. Doing a grep on the PyQt sources I see this only happens in two places outside this class. Maybe the wrapper for the virtual method lacks the /Out/ parameter?
BTW, at least another guy was bitten for this: http://stackoverflow.com/questions/40787663/pyqt5-qquickimageprovider-not-working.
I'm tested it on PyQt5 5.5.1, I'm not sure if it could be fixed in later versions.
Try it, just pip install the latest version into a venv.

Otherwise I would need a short complete example that demonstrates the problem.

Phil
_______________________________________________
PyQt mailing list ***@riverbankcomputing.com
https://www.riverbankcom
Julio César Gázquez
2017-01-05 13:47:50 UTC
Permalink
Post by Phil Thompson
Post by Julio César Gázquez
ImageProvider supports Image type but has not implemented requestImage()
Seems this message comes from Qt's QQuickImageProvider::requestImage() implementation, so it's like the C++ method isn't being overridden by the PyQt's wrapper method.
These methods are somewhat peculiar, as they are virtual methods (and specifically meant to be subclassed) and have an /Out/ parameter. Doing a grep on the PyQt sources I see this only happens in two places outside this class. Maybe the wrapper for the virtual method lacks the /Out/ parameter?
Try it, just pip install the latest version into a venv.
No, I'm afraid it doesn't work even with 5.7.1 (via pip install on
Ubuntu Xenial):

***@marte:~/devel/test$ python3 test.py
ImageProvider supports Image type but has not implemented requestImage()
file:///home/julio/devel/test/test.qml:3:1: QML Image: Failed to get
image from provider: image://images/any.jpg
Post by Phil Thompson
Otherwise I would need a short complete example that demonstrates the problem.
Minimal test example below.

test.py:

from PyQt5.QtCore import QUrl, Qt
from PyQt5.QtGui import QGuiApplication, QImage
from PyQt5.QtQuick import QQuickView, QQuickImageProvider


class ImageProvider(QQuickImageProvider):

def __init__(self):
super().__init__(QQuickImageProvider.Image)

def requestImage(self, id_, requestedSize):
""" Just a red image """
image = QImage(requestedSize.width(), requestedSize.height())
image.fill(Qt.red)
return image, requestedSize


class Application(QGuiApplication):

def __init__(self, argv):
super().__init__(argv)
self._view = QQuickView()
self._view.engine().addImageProvider("images", ImageProvider())
self._view.setSource(QUrl.fromLocalFile("test.qml"))
self._view.show()


if __name__ == '__main__':
app = Application([])
app.exec_()


test.qml:

import QtQuick 2.1

Image {
width: 400
height: 300
source: "image://images/any.jpg"
}

TIA.

Greetings, Julio.

_______________________________________________
PyQt mailing list ***@riverbankcomputing.com
https://www.riverbankcomputi
Phil Thompson
2017-01-09 17:06:13 UTC
Permalink
Post by Julio César Gázquez
Post by Phil Thompson
Post by Julio César Gázquez
ImageProvider supports Image type but has not implemented requestImage()
Seems this message comes from Qt's QQuickImageProvider::requestImage() implementation, so it's like the C++ method isn't being overridden by the PyQt's wrapper method.
These methods are somewhat peculiar, as they are virtual methods (and specifically meant to be subclassed) and have an /Out/ parameter. Doing a grep on the PyQt sources I see this only happens in two places outside this class. Maybe the wrapper for the virtual method lacks the /Out/ parameter?
Try it, just pip install the latest version into a venv.
ImageProvider supports Image type but has not implemented requestImage()
file:///home/julio/devel/test/test.qml:3:1: QML Image: Failed to get image from provider: image://images/any.jpg
Post by Phil Thompson
Otherwise I would need a short complete example that demonstrates the problem.
Minimal test example below.
from PyQt5.QtCore import QUrl, Qt
from PyQt5.QtGui import QGuiApplication, QImage
from PyQt5.QtQuick import QQuickView, QQuickImageProvider
super().__init__(QQuickImageProvider.Image)
""" Just a red image """
image = QImage(requestedSize.width(), requestedSize.height())
image.fill(Qt.red)
return image, requestedSize
super().__init__(argv)
self._view = QQuickView()
self._view.engine().addImageProvider("images", ImageProvider())
self._view.setSource(QUrl.fromLocalFile("test.qml"))
self._view.show()
app = Application([])
app.exec_()
import QtQuick 2.1
Image {
width: 400
height: 300
source: "image://images/any.jpg"
}
TIA.
Should be fixed in tonight's SIP snapshot.

Thanks,
Phil
_______________________________________________
PyQt mailing list ***@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman

Julio César Gázquez
2017-01-09 12:18:50 UTC
Permalink
Post by Phil Thompson
Post by Julio César Gázquez
ImageProvider supports Image type but has not implemented requestImage()
Seems this message comes from Qt's
QQuickImageProvider::requestImage() implementation, so it's like the C++
method isn't being overridden by the PyQt's wrapper method.
Post by Phil Thompson
Post by Julio César Gázquez
These methods are somewhat peculiar, as they are virtual methods
(and specifically meant to be subclassed) and have an /Out/ parameter.
Doing a grep on the PyQt sources I see this only happens in two places
outside this class. Maybe the wrapper for the virtual method lacks the
/Out/ parameter?
Post by Phil Thompson
Try it, just pip install the latest version into a venv.
No, I'm afraid it doesn't work even with 5.7.1 (via pip install on
Ubuntu Xenial):

***@marte:~/devel/test$ python3 test.py
ImageProvider supports Image type but has not implemented requestImage()
file:///home/julio/devel/test/test.qml:3:1: QML Image: Failed to get
image from provider: image://images/any.jpg
Post by Phil Thompson
Otherwise I would need a short complete example that demonstrates the problem.
Minimal test example below.

test.py:

from PyQt5.QtCore import QUrl, Qt
from PyQt5.QtGui import QGuiApplication, QImage
from PyQt5.QtQuick import QQuickView, QQuickImageProvider


class ImageProvider(QQuickImageProvider):

def __init__(self):
super().__init__(QQuickImageProvider.Image)

def requestImage(self, id_, requestedSize):
""" Just a red image """
image = QImage(requestedSize.width(), requestedSize.height())
image.fill(Qt.red)
return image, requestedSize


class Application(QGuiApplication):

def __init__(self, argv):
super().__init__(argv)
self._view = QQuickView()
self._view.engine().addImageProvider("images", ImageProvider())
self._view.setSource(QUrl.fromLocalFile("test.qml"))
self._view.show()


if __name__ == '__main__':
app = Application([])
app.exec_()


test.qml:

import QtQuick 2.1

Image {
width: 400
height: 300
source: "image://images/any.jpg"
}

TIA.

Greetings, Julio.

_______________________________________________
PyQt mailing list ***@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
_______________________________________________
PyQt mailing list ***@riverbankcomputing.com
https://ww
Loading...