Problem loading an image with QImage
-
I am having errors while loadin an image.
I have the images in this path (where I have my Qt project):
QVector<QString> rutas = QVector<QString>(); rutas.push_back("Texturas\plantilla_completa.png"); rutas.push_back("Texturas\plantilla_completa_grises.png");
Then, I call this function to create a texture with that image:
texture::texture(QVector<QString> rutas, QVector<TexturesTypes> tipo) { initializeOpenGLFunctions(); for (int i = 0; i < rutas.size(); i++) { QString filename = rutas[i]; TexturesTypes tipoTextura = tipo[i]; QImage imagen = QImage(filename); QFileInfo info = QFileInfo(filename); std::cout<<info.isSymLink()<<std::endl; std::cout<<info.absoluteFilePath().toStdString()<<std::endl; if(imagen.isNull()) { std::cout<<"ES NULA"<<std::endl; } QOpenGLTexture *texture = new QOpenGLTexture(QImage(filename).mirrored()); if (texture == nullptr) { std::cout << filename.toStdString() << " cannot be loaded" << std::endl; return; } } }
And this is what I have in QImage object and QFileInfo:
.
What's happening? Maybe the path is wrong?
-
What does your std::cout debug output says?
Also I would suggest to not use relative paths since the current working directory my change during runtime. Use QCoreApplication::applicationFilePath() or add your files to a resource file -
QCoreApplication::applicationFilePath() returns C:\Users\Moreno\Documents\Qt\build-PrototipoIluminacion-Desktop_Qt_5_12_1_MSVC2017_64bit-Debug\debug\prototipoIluminacion.exe
And I have my folder called "Texturas" in C:\Users\Moreno\Documents\Qt\build-PrototipoIluminacion-Desktop_Qt_5_12_1_MSVC2017_64bit-Debug\debug , but it is still not working.
This is what I changed and the std::cout:
QString filename = rutas[i]; TexturesTypes tipoTextura = tipo[i]; std::string ruta = QCoreApplication::applicationFilePath().toStdString(); std::cout<<"File path: "<<ruta<<std::endl; std::cout<<"My folder path: "<<filename.toStdString()<<std::endl; QImage imagen = QImage(filename); if(imagen.isNull()) { std::cout<<"IS NULL"<<std::endl; }
This is my textures path:
-
@KillerSmath That solved my problem. Thanks!