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())
{
help_file.append("::/");
help_file.append(topic);
}
HtmlHelp(HWND(winId()),
help_file.toStdWString().c_str(),
HH_DISPLAY_TOPIC,
NULL);
}
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.
Hello, I have include this method into mao project QT. ma I have error :
error C3861: 'winId': identifier not found
what identifies it?
Check this link for more info on
winId
Here is what Qt Documentation has to say about it: