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
$ su - # apt install qt6-webengine-dev
#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.
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
$ ./bin/gcc-15/debug/discord
webview.setHtml("<p>He<b>ll</b>o</p>, c++!");
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:
QCoreApplication::setOrganizationName("MyWorldApplication");
Now, the profile name is MyWorldApplication
#include <QWebEngineProfile>
// This pointer must be got after creating QApplication auto * set = QWebEngineProfile::defaultProfile()->settings();
#include <QWebEngineSettings>
set->setAttribute(QWebEngineSettings::PdfViewerEnabled, true);
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);
#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();
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
Mon May 18 01:10:03 AM UTC 2026
//////////////////////////////////////////////////////////////////////
+
Github:
https://github.com/cppfx/cpphtgt
+
Powered by:
B2 Build
| boost quickbook
+
+