Hi,
I would like to process an image loaded into a Flickable QML element in C++ land but I am failing to obtain the original image. So far I'm only seem able to obtain an image of the QQuickWindow
and would liek to know if there is a way to obtain the whole loaded image.
I am calling a Q_INVOKABLE method of a C++ object as follows:
Flickable {
id: content
clip: false
anchors.fill: parent
boundsBehavior: Flickable.StopAtBounds
Loader {
id: contentLoader
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log("[veo] onClicked - capture triggered")
cplusplusobject.process(contentLoader.item) <----------------- call to C++
}
}
Flickable {
id: content
clip: false
anchors.fill: parent
boundsBehavior: Flickable.StopAtBounds
Loader {
id: contentLoader
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log("[veo] onClicked - capture triggered")
cplusplusobject.process(contentLoader.item) <----------------- call to C++
}
}
To copy to clipboard, switch view to plain text mode
In C++ I have:
void
Cplusplusobject
::process(const QVariant &v
){
qDebug() << "[veo]" << __FUNCTION__;
QQuickItem *item = qobject_cast<QQuickItem *>( v.value<QObject*>() );
qDebug() << "Item dimensions:" << item->width() << item->height();
item->dumpObjectInfo();
QQuickWindow *window = item->window();
QImage image
= window
->grabWindow
();
...
void
Cplusplusobject::process(const QVariant &v)
{
qDebug() << "[veo]" << __FUNCTION__;
QQuickItem *item = qobject_cast<QQuickItem *>( v.value<QObject*>() );
qDebug() << "Item dimensions:" << item->width() << item->height();
item->dumpObjectInfo();
QQuickWindow *window = item->window();
QImage image = window->grabWindow();
...
To copy to clipboard, switch view to plain text mode
The printed item dimensions do correspond to the original image but I fail to see how to turn the QQuickItem into a QImage.
Any suggestions please?
Bookmarks