Notes
All PostsArchive
Android1App Store1C++1Cluster1CSS Specificity1CSS-in-JS1Emotion1Erlang1Input Method1iOS2JavaScript2Loaders1Networking1Node.js1Observables1Prerendering1Qt1React2React Native2RxJS2String Processing1WebEngine1Webpack2Windows2
© 2026 HUANG Cheng
All Posts
Qt and React Hybrid Development
Problem and Exploration A recent project posed an interesting question: how do you render AI chat responses with a typewriter effect inside a Qt app? One…
Feb 18, 2025
Detecting App Store Updates in React Native
Sometimes you ship an exciting new feature and want to prompt users to update right away. NetEase Cloud Music — a React Native app — does exactly this.…
Nov 15, 2024
A Little Pitfall in Erlang String Handling
I stumbled upon echo.opera.com — a service that prints out HTTP request headers — and thought it would be fun to build my own. After implementing echo_rs in…
Sep 26, 2024
Recursion in RxJS
The requirement: after a user selects or photographs an image, send it to an image-recognition API. The API rejects images over a certain size and returns…
Aug 1, 2024
The Mystery Behind RxJS iif
A common pattern in business logic: branch on a precondition to decide which API to call. For order payment, if it's a new order call the create-order…
Jun 22, 2024
React Native Pitfalls and Fixes
Publishing to Android App Stores Rejected for Privacy Violations Some Chinese app stores will reject your app with a message like "SDK reads private user…
Jun 3, 2024
Listing and Switching Input Methods on Windows
Approach 1: Via Keyboard Layout Limitation Extracting the layout ID is non-trivial — the code above uses a simplified low-word extraction. For a thorough…
Apr 20, 2024
Pre-rendering React Apps with Webpack
Background For various reasons — performance, SEO, accessibility — it's desirable for React (or other virtual DOM) apps to serve a static version of the page…
May 7, 2023
Handling CSS-in-JS Style Conflicts
A component library built with was repeatedly getting its styles overridden when integrated into a project that used multiple tech stacks. As you can see in…
Apr 22, 2023
Inside Webpack Loaders and Rules
The Problem A webpack-based React project worked fine on macOS and Linux but threw an error on Windows when processing SCSS: Re-installing and confirmed they…
Sep 29, 2022
Why Doesn't Listening on the Same Port in Multiple Node.js Cluster Workers Throw EADDRINUSE?
The Node.js docs show this pattern without any explanation of why it works: Everyone knows that listening on a port twice throws: And indeed, without : So how…
Sep 26, 2022
Qt and React Hybrid Development

Qt and React Hybrid Development

February 18, 2025

Problem and Exploration

A recent project posed an interesting question: how do you render AI chat responses with a typewriter effect inside a Qt app?

One option is to parse Markdown in C++ and hand the resulting HTML to Qt WebEngine. The other is to delegate both parsing and rendering entirely to Qt WebEngine. The second option is clearly better — there are mature Web solutions for Markdown and animation. Ant Design X provides a complete solution, and markdown-it handles AI-generated Markdown equally well.

Qt WebEngine can load HTML in two ways: from a remote server, or embedded via Qt's resource system. Remote loading sidesteps the issues discussed below but requires server infrastructure. This post explores the embedded approach.

Web App Configuration

There are several ways to scaffold a React app: Vite, Next.js, or webpack from scratch. We chose webpack for two reasons:

  1. We need to customize the build output — specifically, stripping file hashes so we don't have to update CMakeLists.txt on every build.
  2. The project is simple enough that a framework would be overkill.

A minimal webpack.config.js (no hashes):

module.exports = {
  ...
  output: {
    filename: 'app.js',
    publicPath: './',
  },
  resolve: {
    extensions: ['.ts', '.tsx', '.js', '.jsx'],
  },
  plugins: [
    new MiniCssExtractPlugin({
      filename: 'style.css',
    }),
  ],
  ...
};

One important detail: the HTML file must include Qt's qwebchannel.js, which Qt automatically embeds in its resource system:

<script src="qrc:/qtwebchannel/qwebchannel.js"></script>

Without hashes or code splitting, the build produces just three files: index.html, app.js, and style.css. They can then be embedded in the Qt resource system:

qt_add_resources(App "html"
    PREFIX "/"
    FILES
        html/index.html
        html/app.js
        html/style.css
)

Loading Resources and Rendering

The rendering flow follows WebEngine Markdown Editor Example. Since the app needs to handle both historical messages and live AI responses, two objects are registered with Qt WebChannel:

channel->registerObject(QStringLiteral("histories"), &m_histories);
channel->registerObject(QStringLiteral("message"), &m_message);

Historical and user messages render immediately; AI responses get the typewriter effect:

useEffect(() => {
  new QWebChannel(qt.webChannelTransport, function (channel) {
    const histories = channel.objects.histories;
    const message = channel.objects.message;
 
    if (histories.text) {
      setMessages(JSON.parse(histories.text));
    }
 
    history.textChanged.connect((histories: string) => {
      if (histories.length > 0) {
        setMessages(JSON.parse(histories));
      }
    });
 
    message.textChanged.connect((message: string) => {
      if (message.length > 0) {
        setMessages((prev) => [
          ...prev,
          {
            ...JSON.parse(message),
            typing: true,
          },
        ]);
      }
    });
  });
}, [setMessages]);

image.png

image 2.png

Summary

Qt WebChannel provides a JS Bridge that lets JavaScript communicate with native C++ code, making it straightforward to build cross-platform hybrid apps with Qt and React.

#Qt#React#WebEngine