QT QImage Read From Error
-
@mvsri
I really don't understand what is going on! What is it that produces thatimage_path
file? Something external? How do you know that whatever is creating it has finished writing the file and flushed it before your thread decides to read it in, such that it might read in something incomplete? :confused: -
@JonB said in QT QImage Read From Error:
@mvsri
I really don't understand what is going on! What is it that produces thatimage_path
file? Something external? How do you know that whatever is creating it has finished writing the file and flushed it before your thread decides to read it in, such that it might read in something incomplete? :confused:image_path is nothing but a QString which stores the path to a bmp image in a folder. the path is static it doesn't change.
I don't know whether the image writing is finished or not. that's why i used QFile exists to check if the file is created or not and read the image if the path exists.
I also have the same doubt whether i'm reading the image in an incomplete mode.@Christian-Ehrlicher said in QT QImage Read From Error:
@mvsri Maybe try to rename it before you try to read it.
I'm trying it now.
Thank you everyone for all the help. will try to update if i found something useful.
-
@mvsri said in QT QImage Read From Error:
image_path is nothing but a QString which stores the path to a bmp image in a folder. the path is static it doesn't change.
I know that! My question is about the content of that file.
I don't know whether the image writing is finished or not. that's why i used QFile exists to check if the file is created or not and read the image if the path exists.
But that doesn't tell you anything about whether it has started but not finished writing to that file, does it? (Unless you are relying on Windows or something not allowing a file to satisfy "exists" until it has been closed, which I would see as dodgy in the extreme.) In which case, you will read in an incomplete image file, maybe that's why you have "black" at the bottom? At least put in a
qDebug() << image.sizeInBytes()
after loading it (though I'm not sure if that's reliable)....QFile::remove(image_path);
It gets worse! This, or renaming: how do you know that at the instant you execute this the camera has not re-started writing to that file for the next capture, and you are (trying to) removing/renaming a file while it is being written anew?
Is your camera-image-capture-write-to-file a separate process from your code? How do you know when the capture has started/finished writing to the file?