0

I have 2 Qt projects that I've made. One builds a library the other builds a GUI that uses that library. My project with the library includes a bunch of shaders that I've made. Within my GUI I want to reference the path to these shaders. My approach is to have a static function in my library called getLibraryPath() that returns a QString referencing the path on my file system to the library.

I've tried using QDir::currentPath() and QApplication::applicationFilePath() and other similar functions that return paths but they all return paths referencing my GUI's path, not the library's path even though the function to get the path is located inside the library.

Within my GUI I try to reference a shader by doing: Shader->addShaderFromSourceFile(QGLShader::Vertex, MyExternalLib::getLibraryPath() + "/shaders/MyVertexShader.vs");

2 Answers 2

1

A library is just a bunch of code. It has no notion of having its own path. The normal way of doing what you intend to is:

  1. If the library is a separately installed product -- set a registry entry in the installer, and check it at runtime. This will be platform specific, unless the library is written in Qt -- then you can use QSettings, but make sure that you set your company name, application, etc. appropriately as it's not done by QApplication for you anymore.

  2. If the library is installed as a part of your application, in the same folder tree: use QCoreApplication::applicationDirPath() and add a relative path between the application executable and the files you want to this path.

Sign up to request clarification or add additional context in comments.

Comments

0

I was able to solve this by adding the files I want to reference to a qrc file within my library project. By doing this, I could then reference the qrc path and the files inside of them easily.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.