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. [Solved] QGLShader: Unable to open file "vert.vert"
Forum Update on Monday, May 27th 2025

[Solved] QGLShader: Unable to open file "vert.vert"

Scheduled Pinned Locked Moved General and Desktop
13 Posts 5 Posters 14.7k 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.
  • S Offline
    S Offline
    sasmaster
    wrote on last edited by
    #1

    Anyone has idea why my shader program can't read in the vertex shader file ?

    I load the file residing in "Other Files" directory :

    @
    const QString vertexShaderPath="vert.vert";

        if(!m_shader.addShaderFromSourceFile(QGLShader::Vertex,vertexShaderPath )){
    
          qDebug() << m_shader.log();
    }
    

    @

    And getting this:QGLShader: Unable to open file "vert.vert"

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      Well, vert.vert is a path relative to the applications' current path (which is most probably not Other Files). So you either use the correct relative path (probably Other Files/vert.vert) or an absolute path or embed vert.vert as a resource.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sasmaster
        wrote on last edited by
        #3

        Yes it resides in the "Other Files" but that is not a physical location.So in fact it resides in the same folder with the main.cpp .And somehow it is not loaded.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Kxyu
          wrote on last edited by
          #4

          Obviously, main.cpp is located not in compiler destination folder, so for the compiled app the path is incorrect

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            The applications' path may not be main.cpp path (for example when shadow build is used). The easiest way to solve this issue is to include your vert.vert as a resource.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sasmaster
              wrote on last edited by
              #6

              No ,it is not.All the files are under one project folder

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #7

                So what does ... do?
                @
                QFileInfo info("vert.vert");
                qDebug() << info.absoluteFilePath();
                @

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sasmaster
                  wrote on last edited by
                  #8

                  Lukas ,thanks for this tip! Now I see that it retrieves the file from the debug directory which is outside the project folder.I guess it is created when I run in debug mode.How can I change it so that it targets the vert.vert file from the project directory?

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tobias.hunger
                    wrote on last edited by
                    #9

                    Please don't hack around, trying to get the build system to put stuff all over the place! Consider using a proper deployment configuration (aka. a "make install") instead. The build system is generating binaries and assumes that you do not care what it does. The installation is meant to make the application useful by copying files where they need to go. That will make reusing your application/sources way easier for others: You will have less assumptions about your system coded into the build system.

                    In Qt Creator you can add deployment steps for that...

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lgeyer
                      wrote on last edited by
                      #10

                      [quote author="sasmaster" date="1318859574"]Lukas ,thanks for this tip! Now I see that it retrieves the file from the debug directory which is outside the project folder.I guess it is created when I run in debug mode.How can I change it so that it targets the vert.vert file from the project directory?[/quote]

                      You can change the working directory under Projects -> Run. addShaderFromSourceFile() takes either a relative or absolute path. So you can just use "debug/vert.vert" or "../vert.vert" or whatever.

                      But as said, the easiest way to deploy small files with your application is embedding them as a resource. No more fragile tinkering with relative paths. If you do not want to embed it take a look at Tobias post.

                      1 Reply Last reply
                      0
                      • Z Offline
                        Z Offline
                        ZapB
                        wrote on last edited by
                        #11

                        Agreed when using shadow builds the easiest way is to create a resource file and add you shaders to that. Then you can just do ":/vert.vert" from anywhere in your application and not have to worry about relative path issues.

                        Nokia Certified Qt Specialist
                        Interested in hearing about Qt related work

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          sasmaster
                          wrote on last edited by
                          #12

                          Many thanks to all.Being Qt NOOB I knew nothing about resources :) .Now it works just fine.

                          1 Reply Last reply
                          0
                          • Z Offline
                            Z Offline
                            ZapB
                            wrote on last edited by
                            #13

                            No worries. Everybody starts at the beginning. At least you know about resources now and for the future. Happy hacking!

                            Nokia Certified Qt Specialist
                            Interested in hearing about Qt related work

                            1 Reply Last reply
                            0

                            • Login

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