How could I register the files do not under the directories of Qt resource system
-
When I want to make my shader files(developed by glsl) as part of the resource system, it would complain that
the files are not under the folder and need to copy them.The problem is, I don't want to maintain 2(or 2 + n)
same shader files in my codes.Copy the shader files don't look like a good solution.The work around I am thinking is write those shader codes into .cpp files as string const or char const*, what
kind of solution would you suggest?ps : I prefer resource system because I want to make sure the program can find the shader file without any problem
-
Hi,
Have a dedicated folder for your shader files with the corresponding qrc.
What is your project layout ?
-
bq. What is your project layout ?
It looks as following(hope I do not misunderstand your question)
"layout":http://www.flickr.com/photos/92283971@N04/9084832325/
If my explanation seems foggy, please tell me, I will try my best
to make it easier to understand.If the layout like this is a bad idea, please feel free to criticize it.
-
You need to keep the qrc in the ShaderEffect folder.
Where do you load your shaders ? In the application or in the libs ?
-
[quote author="SGaist" date="1371673807"]You need to keep the qrc in the ShaderEffect folder.
Where do you load your shaders ? In the application or in the libs ?[/quote]
In the application, the ShaderEffect folder is a collection of a bunch of
shaders only, without any .pro, .hpp nor .cpp. -
Then you only have to add the qrc in your application pro file and you should be good
-
[quote author="SGaist" date="1371712668"]Then you only have to add the qrc in your application pro file and you should be good
[/quote]I add it into my .pro already
@RESOURCES +=
qrc.qrc@the problem is the resource system of Qt
do not accept the resources which do not under the folder.message of QtCreator when I intent to add the shaders
The file /Users/Qt/program/libs/ShadersEffects/toGray.fsh is not in a subdirectory of the resource file. You now have the option to copy this file to a valid location.
parent/libs/ShaderEffects -- the location of my shaders
parent/apps/colorEnhance -- the location of my app, the .pro and the
qrc are under this folder -
Then try to move the qrc in Shader effects and do
@
RESOURCES += ../ShaderEffects/qrc.qrc
@You might also want to change the qrc name to shaders.qrc it would be cleaner
-
Thanks for your help, as you suggested, change the qrc name would make the project easier to maintain.
-
I add the qrc as you suggested, but there area problem
After I make my "main.qml" become a file in the qrc
the program always complain it cannot find the directory.pro
@
RESOURCES +=
../../experiment_libs/qmlHelper/shaderSupport/support.qrc \
qrc.qrc
@main.cpp
@
#include <QtQuick/QQuickView>
#include <QGuiApplication>
#include <QtDeclarative/QDeclarativeEngine>
#include <QQmlEngine>int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setSource(QStringLiteral("qrc:/main.qml")); view.show(); return app.exec();
}
@
main.qml
@
import QtQuick 2.1import "../../commercial_libs/qmlHelper/shaderSupport"
Rectangle {
width: 100
height: 62Image{ anchors.fill: parent source: "file:///Users/et/Downloads/1360800908784.jpg" ImageEffect{ source: parent } }
}
@
error message
qrc:/main.qml:3:1: "../../experiment_libs/qmlHelper/shaderSupport": no such directory
-
The folder where your application is started is not the same as your source folder.
-
[quote author="SGaist" date="1372248015"]The folder where your application is started is not the same as your source folder.
[/quote]
Yes, I do not put them in the same folder
because it should belongs to other module
if this is the limit of qrc, then I have to find another solutionex :
1 : copy the files of other folder into my source folder
and add them into the qrc, could .pro handle this kind of jobs?
Or I have to write some script according to different platforms?
Maybe use Qt to write a simple app to handle the cross platform
issues would be a better solution2: just wrapped those shader codes as .hpp and .cpp
The second solution
-
Wait: what do you want to import from that path ?
If it's the shaders, since you have them in your qrc get them from the qrc
-
Part of them are qrc, part of them are qml components
I was confuse by the error messages, looks like I could access
the shaders in qrc even it is not under my source foldersNow the problem is how could I access the qml do not under
my source folder(ImageEffect in main.qml)? -
qrc is meant for that, embed the file in your executable so your don't have to get them from your hard drive.
Note that it's not a "put in everything" solution. You can't take tones of megabytes and have them built in your executable (I am not saying it's your case, it's just a warning)
As for the qml side, I'm sorry but I have not yet any expertise with it. But IIRC there have been several post on the subject
-
[quote author="SGaist" date="1372251293"]
As for the qml side, I'm sorry but I have not yet any expertise with it. But IIRC there have been several post on the subject[/quote]Thanks for your replies, don't worry
I have no intent to make every thing become part of my
executeable, what I want to do is make sure the resource files
like shaders, icons and qml could be loaded without too much
headaches.