Unsolved Failed to get image from provider
-
Hi @mrjj ,
I am trying to use the image provider that's why I usedimage.source = "image://pix/" + fileDialog.fileUrl `` I am trying to create a pixmap and use QML to save it to localstorage.
-
@gabor53
Hi
Ok, but are you sure the QQuickImageProvider should be involved in the
saving of the image?
The syntax "image://pix/" seems for loading only, docs mention nothing about saving.
Anyway, i was just wondering. -
@gabor53 said in Failed to get image from provider:
@SGaist ,
Yes. According to qDebug the content isMakePix requestPixmap id: "file:///C:/Users/gabor/Pictures/133CANON/IMG_3344.jpg ``
You need to remove
file:///
from that URL, otherwise QPixmap won't handle it.As others note, however - it seems you don't need an image provider here at all. QML can handle JPG images out of the box.
-
Hi @sierdzio ,
It is true, but how can I save the jpg to localstorage?
Thank you. -
You mean you want to take the jpg from one location and save it in another? Use QFile::copy().
-
@sierdzio
I want to save the actual image to a db. -
@mrjj,
The goal is to save the actual jpg into Qt Quick Local Storage. To do that I need to create a Blob from the jpg file. I don't think it is possible to do in QML; that's why I use QQuickImageProvider to send the image from QML to C++ and return a pixmap to QML.
If I copy 1.jpg to the qml folder and pass1.jpg to QQuickImageProvider the image is correctly displayed, which means the path I get from fileDialog.fileUrl is incorrect.
How can I fix the path so fileDialog.fileUrl provides the right path to the image?
Thank you. -
@sierdzio already answered that question.
-
hi
so you get a pixmap back to QML but how do you then convert it to the blob?
As far as i understand, Qt Quick Local Storage is a sqllite database so
you need it as QbyteArray to save it. -
@mrjj
Is there a way to convert pixmap into blob in QML? -
@gabor53
Hi
sadly i dont know QML well enough to answer that.
It seems it get converted to ArrayBuffer if used in signals.
from c++ to QML.
but im not sure how you can get the pixmap into that. -
Did you already check Qt Quick Local Storage QML Types ?
By the way, why do you want to store images there ?
-
@SGaist ,
I checked Local Storage QML Types but it doesn't really talk about images.
I'm creating a small app where I can store an image and a description of the image. I used to do it by storing only the url, but eventually the images got moved and I ended up with a bunch of broken links. -
In that case, I would rather go with a more classical approach through C++ especially if you want to recover the images.
-
@SGaist
Thank you. I will do it that way.