PDA

View Full Version : Resource search/lookup tool/script to check completeness and correctness of qrc files



ghorwin
25th January 2022, 07:41
Hi all,

I have a large project with 200+ resource files (mostly pixmaps) and need to do refactoring/directory structure changes.

Now my pixmaps are used all over the code base with typical qrc reference paths: ":/master/arrow_16x16/right/background/arrow_right_middle.png", both in cpps and ui-files.

When I now modify my qrc file and move the referenced pixmaps in the directory structure, I have several situations:

- pixmap is referenced in qrc and correctly used in the source code
- source code contains invalid qrc-path (not detected at compile time, and difficult to find through testing)
- pixmap is referenced in qrc but nowhere used (i.e. unused and could be deleted)
- pixmap is in directory structure but not (yet) referenced in qrc (i.e. unused and could be deleted)

Obviously, cases 2 to 4 are suboptimal, yet, it is very time consuming to detect such problems and clean out the code base and directory structure.

Does anyone know of a tool/script that:

- scans a base directory of resources
- reads a project's qrc file (or files)
- scans the source code (cpp and ui) for string constants with pattern ":/*.png" or any other suitable extension

and then prints out a nice summary of all resources used and unused and files, i.e. the 4 categories above?

Thanks for any suggestions,
Andreas

d_stranz
25th January 2022, 18:10
Does anyone know of a tool/script that:

I don't know of a tool, but QRC files are basically XML so can be read and processed like any normal ASCII file. It probably would not be too hard to write a python program to 1) read each <file> entry from the QRC file, 2) verify that the file exists on disk (if needed), and 3) matches the use in a cpp / h file. For step 3, you could fire off grep with the filename as the target to match so you wouldn't have to write that part.

ghorwin
27th January 2022, 08:48
I agree - writing such a tool wouldn't be too hard. How about a challenge - how may hours of work will it take to get a decent tool written?

It should:

- generate a list of resources, categorized as described
- clean out qrc-file(s) from unused resources
- offer the functionality to remove unused pixmaps from directory structure

My guess: 1-2 days, maybe faster.

Questions:

- Project name? "ResourceCleanser" or "QrcChecker" or ...
- Programming language? Qt-Gui-Tool or Python command line tool?

d_stranz
27th January 2022, 16:33
Hah. It would have to be a weekend project for me. Since I am trying to teach myself Python, I would probably use that with PyQt. Probably QrcChecker would be a more descriptive name. I'll think about it.

ghorwin
7th February 2022, 21:06
Not quite a weekend project (to many other projects), but done in a little less than 20 working hours.

So, here it is: the first real QRC-Checker: https://github.com/ghorwin/QrcChecker

Mind: this is a simple tool, only basic error checking included, but already with some convenience. Most of all, it does its job for me.

As always, if you need anything special, just hack away. Since this is a tool for the Qt coding community, I didn't bother with creating installers and the like... just clone the repo, compile and be happy!

PS: I'd appreciate (hopefully positive :-) ) feedback!

d_stranz
8th February 2022, 16:25
My version is nearly done as well, in probably about the same amount of time. We can compare features once I have finished (probably next weekend).