Miscellaneous#

Add Icon (CMake)#

We first need to prepare our .ico file :

  1. Create a .png with a size of 64x64

  2. Download and install ImageMagick’s convert tool

  3. From a command prompt, run magick convert nameofpng.png nameoficon.ico

You now have your icon file.

  1. Create a file appicon.rc with the following line inside : IDI_ICON1 ICON DISCARDABLE "path/to/icon/icon.ico"

  2. Open your CMake script and, under add_executable(), add "path/to/script.rc"

Your program should now create your .exe with your icon packed !

Logger#

If you want to have a simple, well-formatted, automatic file location, timestamp’ed logger, the following repo contains two files that can be included in your Qt project (they are standalones files).

Formatted output

To use it, call installFormattedColorOutput(bool usecolor); at the beginning of your main.

Note

Some terminals may not support colors (like CMD on Windows).
If you try to enable colors, you will see gibberish around your message.

Note

Enabling it will also modify the behavior of qDebug(), qInfo() ... while adding a (colored) header stating the current debug level.

Afterward, simply use one of the provided macro to log your messages with information in which file and on which line the statement is located :

FDEBUG("Debug msg");
FINFO("Info msg");
FWARN("Warn msg");
FCRITICAL("Critical msg");
FFATAL("Fatal msg");
FLN(); // for simple line return without debug data

Standard Qt functions like qDebug() can still be used. They will have the log level as header.

QT CMake