Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem loading an image with QImage
Forum Updated to NodeBB v4.3 + New Features

Problem loading an image with QImage

Scheduled Pinned Locked Moved Solved General and Desktop
qimageerrorqopengltexturepathimage
5 Posts 3 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JesusM
    wrote on 21 Apr 2019, 11:54 last edited by
    #1

    I am having errors while loadin an image.
    I have the images in this path (where I have my Qt project):
    0_1555847594422_Captura.PNG

    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:

    0_1555847491916_Captura.PNG .

    What's happening? Maybe the path is wrong?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 21 Apr 2019, 12:55 last edited by
      #2

      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

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      J 1 Reply Last reply 23 Apr 2019, 09:19
      1
      • C Christian Ehrlicher
        21 Apr 2019, 12:55

        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

        J Offline
        J Offline
        JesusM
        wrote on 23 Apr 2019, 09:19 last edited by
        #3

        @Christian-Ehrlicher

        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;
                }
        
        

        0_1556011028650_Captura.PNG

        This is my textures path:

        0_1556011133821_Captura.PNG

        K 1 Reply Last reply 23 Apr 2019, 09:26
        0
        • J JesusM
          23 Apr 2019, 09:19

          @Christian-Ehrlicher

          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;
                  }
          
          

          0_1556011028650_Captura.PNG

          This is my textures path:

          0_1556011133821_Captura.PNG

          K Offline
          K Offline
          KillerSmath
          wrote on 23 Apr 2019, 09:26 last edited by
          #4

          @JesusM
          Use QCoreApplication::applicationDirPath() instead of QCoreApplication::applicationFilePath()

          @Computer Science Student - Brazil
          Web Developer and Researcher
          “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

          J 1 Reply Last reply 23 Apr 2019, 09:50
          3
          • K KillerSmath
            23 Apr 2019, 09:26

            @JesusM
            Use QCoreApplication::applicationDirPath() instead of QCoreApplication::applicationFilePath()

            J Offline
            J Offline
            JesusM
            wrote on 23 Apr 2019, 09:50 last edited by
            #5

            @KillerSmath That solved my problem. Thanks!

            1 Reply Last reply
            0

            2/5

            21 Apr 2019, 12:55

            • Login

            • Login or register to search.
            2 out of 5
            • First post
              2/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved