PDA

View Full Version : QDir::setCurrent with resource files



LarryERamey
18th April 2011, 20:35
Is there a way to change the current directory to something in the resource directory? for example:



QDir dir(":/resources/html");

dir.setFilter(QDir::Files | QDir::NoSymLinks);
dir.setSorting(QDir::Name);
QFileInfoList list = dir.entryInfoList();

Q_ASSERT(QDir::setCurrent(":/resources/html"));



I nthe above example, list has exactly the files in It I think it should, but the program keeps quitting because the setCurrent call is returning false.

Can I simply not do what I am trying to do here?

jmeb2206
19th April 2011, 03:47
I think you should call like this instead



QDir::setCurrent(dir.absolutePath());

LarryERamey
19th April 2011, 16:29
That does not work either. Thanks though.....

jmeb2206
20th April 2011, 02:21
Yea most likely because absolutePath in your case is not giving a fully qualified path which I assume is what setCurrent is wanting. I use the Qt Resource System too and I compile it into the executable. For instance ":/<myprefix>" is resource data compiled into the application for immediate access. I'm not confident that you can do what you are trying as ":/<prefix>" are resource paths and not your typical file system paths. Hopefully I said something useful. Cheers and good luck.