This is called URL Protocol Handler and you were following the right path of modifying the registry. HKEY_CLASSES_ROOT
in fact maps to either HKEY_LOCAL_MACHINE\Software\Classes
(which can have issues with write access) and HKEY_CURRENT_USER\Software\Classes
, we use the latter.
Note : Ensure that Qt is compiled, and build the application using the release mode of Qt Creator, not the debug mode.
Here's the complete example that works:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QApplication> | |
#include <QSettings> | |
#include <QDir> | |
int main(int argc, char *argv[]) { | |
QApplication a(argc, argv); | |
QString path = QDir::toNativeSeparators(qApp->applicationFilePath()); | |
QSettings set("HKEY_CURRENT_USER\\Software\\Classes", QSettings::NativeFormat); | |
set.beginGroup("YourApp"); | |
set.setValue("Default", "URL:YourApp Protocol"); | |
set.setValue("DefaultIcon/Default", path); | |
set.setValue("URL Protocol", ""); | |
set.setValue("shell/open/command/Default", QString("\"%1\"").arg(path) + " \"%1\""); | |
set.endGroup(); | |
return 0; | |
} |