All Products
Search
Document Center

HTTPDNS:Integrate DoH with Qt WebEngine

Last Updated:Mar 17, 2026

This topic provides key code snippets and configuration details for using DNS over HTTPS (DoH) in Qt WebEngine applications.

1. Introduction

Starting from version 6.6, Qt WebEngine supports DNS over HTTPS (DoH). This feature enables developers to perform DNS resolution over the encrypted HTTPS protocol to prevent DNS hijacking in web applications. HTTPDNS is an Alibaba Cloud service designed for mobile apps and Internet of Things (IoT) devices. It provides stable, secure, and precise public recursive resolution. This topic describes how to integrate the HTTPDNS DoH service into a Qt WebEngine application.

2. Prerequisites

Before you integrate DoH with Qt WebEngine, make sure you have configured the DoH service.

3. Configuration

Integration with the HTTPDNS DoH service is configured primarily through the QWebEngineGlobalSettings::DnsMode API.

The configuration includes two parts:

  • Safe mode (secureMode): Determines the usage priority between DoH and local DNS and controls DNS resolution policies and backoff mechanisms in different network environments.

  • Server templates (serverTemplates): Specifies the list of DNS over HTTPS (DoH) services, defines the endpoints of available DoH servers, and supports multiple servers to provide high availability.

The following code is an example:

// DoH configuration
QWebEngineGlobalSettings::DnsMode dnsMode;
dnsMode.secureMode = QWebEngineGlobalSettings::SecureDnsMode::SecureWithFallback;
dnsMode.serverTemplates = QStringList{
 "https://xxxx.com/dns-query{?dns}"
};
QWebEngineGlobalSettings::setDnsMode(dnsMode);
// After configuring DoH, create a WebEngineView and load a web page
QWebEngineView *webView = new QWebEngineView();
webView->load(QUrl("https://www.example.com"));
webView->show();

4. Configuration notes

  • DoH integration template format: The template must include the {?dns} parameter.

    • Correct example: "https://xxxx.aliyunhttpdns.com/dns-query{?dns}"

    • Incorrect example: "https://dns.xxxx/dns-query" (The {?dns} parameter is missing.)

    • Incorrect example: "https://1.1.X.X/dns-query?dns=" (Incorrect parameter format.)

  • DoH configuration is global

    • You can set it via QWebEngineGlobalSettings.

    • You must complete the configuration before creating any QWebEngineView instance.

    • After the configuration is complete, all subsequent WebEngineView instances automatically use the DoH settings.

  • High availability configuration

    • We recommend that you use the SecureWithFallback pattern to prevent business impact if DoH becomes unavailable in extreme scenarios.

    • Configure multiple DoH servers as a fallback solution. Use HTTPDNS as the primary DoH service and other backup DoH services, such as free public DoH services, for disaster recovery.

5. Summary

This topic outlined how to integrate DNS over HTTPS (DoH) in Qt WebEngine applications, including basic configuration, safe mode selection, and high availability deployment strategies. After configuration, verify the DoH integration by capturing packets to view HTTPS requests, checking DNS logs, or performing network fault tests. To ensure stability in a production environment, use the SecureWithFallback mode and configure multiple DoH servers.