Unsolved Received image from socket in requestImage of(Image provider) in Qt 5.12.9
-
I want to received image from socket in requestImage function.
-
@Pooja-Bhusare said in Received image from socket in requestImage of(Image provider) in Qt 5.12.9:
requestImage function
What is this function? Your own?
See https://doc.qt.io/qt-5/qnetworkaccessmanager.html
And please provide more information, not just a short sentence. -
QImage QmlImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
printf("In request function ..\n");
image.load("/home/abc.png");
return image;
}
Above function is working but i want to collect image from socket how to call socket function from requestImage function? -
@Pooja-Bhusare So, you want to download an image from somewhere on network/Internet? Then please read the link I posted and take a look at Qt networking examples.
Or is the image located on a network drive?
Please explain more clearly! -
@jsulm
I have implement the socket programming in QT too mns reading the image through socket using bytearray and converting that array into QImage but how to pass that Image to requestImage function.Ex:
void abc_read_bytearray_socket()
{
// Read data from socket
// convert into QImage
}QImage QmlImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
printf("In request function ..\n");
image.load("/home/abc.png");
return image;
} -
@Pooja-Bhusare said in Received image from socket in requestImage of(Image provider) in Qt 5.12.9:
but how to pass that Image to requestImage function.
requestImage should not return that image as networking is asynchronous (non-blocking). Instead requestImage should only request the image and as soon as the image was received you can emit a signal and pass the image as signal parameter.
-
@jsulm sorry could you explain little bit more ?
it mns i need to use signal and slot concept here .
once i get image from socket i need to send signal to requestImage function ?
or please correct my understanding -
@Pooja-Bhusare said in Received image from socket in requestImage of(Image provider) in Qt 5.12.9:
once i get image from socket i need to send signal to requestImage function ?
No, you don't send a signal to anywhere. You just emit the signal. What ever slot is connected to this signal will be called then.
Your approach to return the image from requestImage would block your UI until the image was received which is not good. That's why I suggested to not to return the image from requestImage. requestImage would only trigger the image download and not return anything. Then:void abc_read_bytearray_socket() { // Read data from socket // convert into QImage emit imageReceived(image); }