That’s right, I’ve written several programs with Qt5 in Genode, and first of all, I have to say it’s amazing. Up until now, there have been no issues. The problem only appeared when I added the WebView
to the program. (I couldn’t find a suitable space to share the files, so I’ll post the code here.)
File: main.cpp
static inline QApplication & web_engine_initialization(Libc::Env &env) {
qpa_init(env);
const char *argv[] = {
"kiosk",
"--single-process",
"--enable-logging",
"--log-level=3",
"--v=0",
"--use-fake-device-for-media-stream",
0
};
int argc = 7;
static QApplication app(argc, (char**)argv);
QFile file(":style.qss");
if (!file.open(QFile::ReadOnly)) {
qWarning() << "Warning:" << file.errorString()
<< "opening file" << file.fileName();
} else {
qApp->setStyleSheet(QLatin1String(file.readAll()));
}
app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit()));
return app;
}
struct Main {
Libc::Env &env;
QApplication &app { web_engine_initialization(env) };
QMember<Kiosk> kiosk { };
Main(Libc::Env &env) : env(env) {
kiosk->show();
}
};
void Libc::Component::construct(Libc::Env &env) {
Libc::with_libc([&] {
static Main main { env };
exit(main.app.exec());
});
}
File: kiosk.h
class Kiosk : public Compound_widget<QWidget, QVBoxLayout> {
Q_OBJECT
private:
QMember<QLineEdit> _urlInput;
QMember<QPushButton> _reloadButton;
QMember<QWebEngineView> _webView;
QString _configUrl;
public:
Kiosk();
~Kiosk() {}
private slots:
void loadUrl();
void checkNetworkConnection(std::function<void()> callback);
};
File: kiosk.cpp
Kiosk::Kiosk(): _reloadButton("Reload"), _configUrl("https://www.google.com") {
_urlInput->setPlaceholderText("Enter URL...");
_layout->addWidget(_urlInput);
_layout->addWidget(_reloadButton);
_layout->addWidget(_webView);
connect(_reloadButton, &QPushButton::clicked, this, &Kiosk::loadUrl);
loadUrl();
}
void Kiosk::loadUrl() {
QString urlText = _urlInput->text().trimmed();
if (!urlText.startsWith("http://") && !urlText.startsWith("https://")) {
urlText = "https://" + urlText;
}
_configUrl = urlText;
checkNetworkConnection([this]() {
_webView->load(QUrl(_configUrl));
});
}
void Kiosk::checkNetworkConnection(std::function<void()> callback) {
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkRequest request(QUrl("http://www.google.com"));
QNetworkReply *reply = manager->get(request);
connect(reply, &QNetworkReply::finished, this, [reply, callback]() {
if (reply->error() == QNetworkReply::NoError) {
callback();
} else {
QMessageBox::critical(nullptr, "Network Error", "No network connection.");
}
reply->deleteLater();
});
}
I ran this code. Simply removing the line _layout->addWidget(_webView);
causes no resource issues. However, with this line included, the entire system freezes. After the error occurs, the system exits the frozen state, but the Kiosk module becomes unusable.