PrevUpHomeNext

c++ Qt WebEngine and b2 build


> Start
> Install
> Hello World: Discord App
> Use b2 build
> Address Bar
> Default Profile
> Customize Profile
> Tabs
> Back: Home

c++

Qt6

Qt WebEngine

Chromium

B2 Build

Discord

c++ qt webengine is a web browser engine powered by Qt c++ libraries and google chromium.

c++ Examples

c++ Code

Install

$ su -
# apt install qt6-webengine-dev

Hell World: Discord App

#include <QApplication>
#include <QWebEngineView>
#include <QUrl>
#include <iostream>

int main(int argc, char ** argv)
{
	QApplication app{argc, argv};
	QWebEngineView view;
	view.load(QUrl("https://discord.com"));
	view.resize(1500, 850);
	view.show();
	return app.exec();
}

Compile it with c++ compiler (gcc), run, then open discord, login, and chat.

Use b2 build

Initialize project

$ mkdir discord
$ cd discord
$ kak discord.cpp
$ kak jamroot

File: jamroot

import pkg-config ;
using pkg-config ;

pkg-config.import
	qt6_webengine
:
	requirements
		<name>Qt6WebEngineWidgets
;

exe
	discord
:
	discord.cpp
:
	<library>qt6_webengine
;

The jamfile jamroot has too many lines? It has only four lines actually:

import pkg-config ;
using pkg-config ;
pkg-config.import qt6_webengine : requirements <name>Qt6WebEngineWidgets ;
exe discord : discord.cpp : <library>qt6_webengine ;

Build project

b2 -q -j3

Run discord

$ ./bin/gcc-15/debug/discord

setHtml

webview.setHtml("<p>He<b>ll</b>o</p>, c++!");

Address Bar

Add address bar to the program, which will make the program look like a web browser.

#include <QApplication>
#include <QWebEngineView>
#include <QUrl>
#include <iostream>
#include <QVBoxLayout>
#include <QLineEdit>

int main(int argc, char ** argv)
{
	QApplication app{argc, argv};
	auto * window = new QWidget;
	window->resize(1500, 800);
	auto * layout = new QVBoxLayout{window};

	// Create an address bar to the program.
	auto * addressbar = new QLineEdit;
	layout->addWidget(addressbar);

	auto * webview = new QWebEngineView;
	layout->addWidget(webview);

	// Connect address bar url input event.
	QObject::connect(
		addressbar,
		&QLineEdit::returnPressed,
		[webview, addressbar]
		{
			QString url = addressbar->text();
			if (! url.startsWith("https://") && ! url.startsWith("http://"))
				url = QString{"https://"} + url;
			std::cout << "Trying connect:\n" << url.toStdString() << "\n..." << std::endl;
			webview->load(QUrl(url));
		}
	);

	window->show();
	return app.exec();
}

Default Profile

Default profile:

Profile name:

QCoreApplication::setOrganizationName("MyWorldApplication");

Now, the profile name is MyWorldApplication

Get settings pointer

#include <QWebEngineProfile>

// This pointer must be got after creating QApplication
auto * set = QWebEngineProfile::defaultProfile()->settings();

Enable/Disable features

#include <QWebEngineSettings>

set->setAttribute(QWebEngineSettings::PdfViewerEnabled, true);

Customize Profile

auto * profile = new QWebEngineProfile("MyNewProfile", this);
profile->settings->setAttribute(QWebEngineSettings::JavascriptEanbled, false);
auto * page = new QWebEnginePage(profile, this);
auto * webview = new QWebEngineView(this);
webview->sePage(page);

Tabs

#include <QTabWidget>
#include <QWidget>

auto * tab1 = new QWidget;
auto * tab2 = new QWidget;

QTabWidget twg;

twg.addTab(tab1, "Tab 1");
twg.addTab(tab2, "Tab 2");

twg.resize(1500, 850);
twg.show();

//////////////////////////////////////////////////////////////////////

Home

//////////////////////////////////////////////////////////////////////

Mon May 18 01:10:03 AM UTC 2026

//////////////////////////////////////////////////////////////////////

Helpful

Jfty

Wtgo

Role

+

Github:
https://github.com/cppfx/cpphtgt

+

Powered by:
B2 Build | boost quickbook

+

Donate

+

@cppfx.xyz


















PrevUpHomeNext