QImageReader: File not found
-
@kkgg What is your actual question?
@Christian-Ehrlicher
Hello, I developed my own program and used ImageReader to read an image. After I read it many times, it gave me the error "File not found", but my file did exist.
I try to use Qimage QImageReader and QFile, both show "File not Found"
I seem to feel that it has something to do with memory, because when I read the n+1th picture, the first picture will produce this phenomenon -
@Christian-Ehrlicher
Hello, I developed my own program and used ImageReader to read an image. After I read it many times, it gave me the error "File not found", but my file did exist.
I try to use Qimage QImageReader and QFile, both show "File not Found"
I seem to feel that it has something to do with memory, because when I read the n+1th picture, the first picture will produce this phenomenon@kkgg you should show some code. Best a minimal, compileable example.
-
@kkgg you should show some code. Best a minimal, compileable example.
QImage pic = QImage(i); pic = pic.scaled(200, 200, Qt::KeepAspectRatio, Qt::FastTransformation); QLabel *m_label = new QLabel(this); m_label->setPixmap(QPixmap::fromImage(pic)); ui->tableWidget->setCellWidget(count , 1, cl_label);
I guess it's not a code problem. I just loaded a picture and put it into a QLabel, and then put the QLabel into QTableWIdget. After reading about 80 pictures, the first one could not be read. I try to find the error with QImageReader, it says "File not found",
tried using QImageReader::setAllocationLimit(8192);, which can increase the number that can be read -
QImage pic = QImage(i); pic = pic.scaled(200, 200, Qt::KeepAspectRatio, Qt::FastTransformation); QLabel *m_label = new QLabel(this); m_label->setPixmap(QPixmap::fromImage(pic)); ui->tableWidget->setCellWidget(count , 1, cl_label);
I guess it's not a code problem. I just loaded a picture and put it into a QLabel, and then put the QLabel into QTableWIdget. After reading about 80 pictures, the first one could not be read. I try to find the error with QImageReader, it says "File not found",
tried using QImageReader::setAllocationLimit(8192);, which can increase the number that can be readI don't see where you load an image here or is 'i' a string? You should check with QFile::exists () if the file really exists. QImageReader does not do something special. It simply opens the file with QFile so I doubt there is an error in there. Simplify your code and create a minimal compileable example or the problem goes away and you found your bug.
-
QImage pic = QImage(i); pic = pic.scaled(200, 200, Qt::KeepAspectRatio, Qt::FastTransformation); QLabel *m_label = new QLabel(this); m_label->setPixmap(QPixmap::fromImage(pic)); ui->tableWidget->setCellWidget(count , 1, cl_label);
I guess it's not a code problem. I just loaded a picture and put it into a QLabel, and then put the QLabel into QTableWIdget. After reading about 80 pictures, the first one could not be read. I try to find the error with QImageReader, it says "File not found",
tried using QImageReader::setAllocationLimit(8192);, which can increase the number that can be read@kkgg
Please start by following @Christian-Ehrlicher's instructions.However, FWIW, you/ @Christian-Ehrlicher might like to read https://forum.qt.io/topic/68238/qimagereader-file-not-found.
After a few clicks Qimagereader return a "File not found" error even if the image exists (the image is the same).
all images is loaded correctly, but after few clicks it doesn't work anymore.
That is from 2016, yet apparently reports this "strange" behaviour. It did not seem to be resolved.
Is this a timing thing for loading rapidly? Once it goes wrong and says "file not found", if you try to load again does that work or once it is in this state does it never load?
-
@kkgg
Please start by following @Christian-Ehrlicher's instructions.However, FWIW, you/ @Christian-Ehrlicher might like to read https://forum.qt.io/topic/68238/qimagereader-file-not-found.
After a few clicks Qimagereader return a "File not found" error even if the image exists (the image is the same).
all images is loaded correctly, but after few clicks it doesn't work anymore.
That is from 2016, yet apparently reports this "strange" behaviour. It did not seem to be resolved.
Is this a timing thing for loading rapidly? Once it goes wrong and says "file not found", if you try to load again does that work or once it is in this state does it never load?
-
@JonB @Christian Ehrlicher "i" is a path, an actual path. I am sure it exists, but using QFile::exists () shows that it does not exist.
fileDialog.getOpenFileNames(this,"OpenImage","", "Files(*.jpg);;Files(*.png)");
This is how I get the path
-
@kkgg said in QImageReader: File not found:
I am sure it exists, but using QFile::exists () shows that it does not exist.
If
QFile::exists()
says it does not then it does not. What exactly is the path you are using?@JonB I'm sure it exists, because when I don't read n+1 pictures, the first one will not disappear.
I guess it has something to do with memory, because when I use QImageReader::setAllocationLimit(8192), the number of Qimages that can be read will increase. The version I use is Qt6.6, and my development environment is Android.
The fuzzy part is Chinese, and the road Jin is a fixed string. I used fileDialog.getOpenFileNames(this,"OpenImage","", "Files(.jpg);;Files(.png)"); to get it string
-
@JonB @Christian Ehrlicher "i" is a path, an actual path. I am sure it exists, but using QFile::exists () shows that it does not exist.
fileDialog.getOpenFileNames(this,"OpenImage","", "Files(*.jpg);;Files(*.png)");
This is how I get the path
@kkgg
Hmm, I know nothing about Android, but this may be relevant. Maybe there is an Android issue over time? I don't suppose you can copy the file to somewhere non-Android to check? Probably not, this path means you are running under Android and have access only to its filing system?Please also make 100% clear: you have fuzzed-out some of the filename for privacy, fair enough. But does that blanked-out area contain anything about a "counting
i
" you mention, so it varies, or is it a fixed string?I guess it has something to do with memory, because when I use QImageReader::setAllocationLimit(8192), the number of Qimages that can be read will increase.
Ah, well, isn't that what you have to do then if you want to read more than 80 or whatever? Even if you are passing the same path I would guess that a separate image must be created/stored on each call, since, for example, code would not know whether the content had changed so presumably cannot "share" the resulting image.
Having said that, I read
QImageReader::setAllocationLimit()
as a limit on one call to load one image, not some "cache" applicable across all images loaded.I still find it hard to believe that
QFile::exists()
sometimes returns false. Unless it's an Android issue. -
@kkgg
Hmm, I know nothing about Android, but this may be relevant. Maybe there is an Android issue over time? I don't suppose you can copy the file to somewhere non-Android to check? Probably not, this path means you are running under Android and have access only to its filing system?Please also make 100% clear: you have fuzzed-out some of the filename for privacy, fair enough. But does that blanked-out area contain anything about a "counting
i
" you mention, so it varies, or is it a fixed string?I guess it has something to do with memory, because when I use QImageReader::setAllocationLimit(8192), the number of Qimages that can be read will increase.
Ah, well, isn't that what you have to do then if you want to read more than 80 or whatever? Even if you are passing the same path I would guess that a separate image must be created/stored on each call, since, for example, code would not know whether the content had changed so presumably cannot "share" the resulting image.
Having said that, I read
QImageReader::setAllocationLimit()
as a limit on one call to load one image, not some "cache" applicable across all images loaded.I still find it hard to believe that
QFile::exists()
sometimes returns false. Unless it's an Android issue.