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 = "")
	if (!topic.isEmpty())

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.

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

  1. Hello, I have include this method into mao project QT. ma I have error :
    error C3861: 'winId': identifier not found
    what identifies it?

    1. Check this link for more info on winId
      Here is what Qt Documentation has to say about it:

      Returns the window system identifier of the widget.
      Portable in principle, but if you use it you are probably about to do something non-portable. Be careful.
      If a widget is non-native (alien) and winId() is invoked on it, that widget will be provided a native handle.
      This value may change at run-time. An event with type QEvent::WinIdChange will be sent to the widget following a change in window system identifier.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.