How to Open CHM Files and Topics in C++/Qt (Using Windows API)

In Qt/C++ you can open Compiled HTML Help files (*.CHM files) quite easily with a simple Win32 API function named HtmlHelp. In this post I have shared a wrapper function that you can copy and paste in your Qt/C++ code and use.

Well, first of all, here is the wrapper function:

void qHtmlHelp(QString help_file, QString topic = “”)

This function has two parameters.

  • help_file: You need to provide a CHM file path for this. (Example: “C:\MyApp\Help.CHM”)
  • topic: This needs to be set to a topic inside the CHM file. (For example: “introduction.htm”)

Please note that for this function to work, you need to add the following includes in your code:

#include “Windows.h”
#include “HtmlHelp.h”

And also you need to add the following libraries to your Qt Project (*.PRO) file:

LIBS += -lAdvapi32 -lHtmlhelp

The line above is the same as telling the Compiler to look in Advapi32.lib and HtmlHelp.lib for external dependecies.

One last thing to note is that you can use this function to add context sensitive help to your Qt/C++ application.

Leave a Reply

Your email address will not be published. Required fields are marked *