Update: Using QML instead? Click here to find out how you can use it in your QML app.

Update 2: The script can now generate a javascript file as well to be used in a QML app.

I was working on one of my projects and I thought it would be convenient to use Font Awesome instead of separate icon files for different icons (I love Font Awesome, thanks Dave Gandy!. I googled a bit and found some scripts/icon engines that would do this work but I tried none. I didn’t want to include any third party library. I wanted it to be simple. Qt is famous for its simplicity not just for UI implementation but for all of its rich APIs. Thankfully, I came up with a very simple solution. I had to write a simple script (thanks to Qt again) to generate a header file which contained all the Font Awesome icon names and their corresponding unicode values.

The script that will generate the header file named FontAwesomeIconNames.h or FontAwesomeIconNames.js depending on the mode you select:

After compiling the file, you will have FontAwesomeUtilityGenerator binary. The usage is - ./FontAwesomeClassGenerator –cssfilepath /path/to/font-awesome.css –mode [c++|qml] [–outputpath /outputpath/] . The –mode argument determines whether you want a header file generated or a javascript file (for QML). The default mode is c++. The –outputpath argument is optional. If you use it, the header file will be saved to the provided path. If you do not use it, the header file will be exported to the folder where you have the binary. Please provide the path to the non-minified version of the CSS file.

First of all, this is what you’d have to do in the main() method of your software.

And finally, enjoy :D

P.S. the icon names are the default ones found on the Font Awesome website here.