initialization and cleanup

This commit is contained in:
2026-03-17 15:42:03 +01:00
parent 7c3b780ae9
commit c50267120a
9 changed files with 209 additions and 216 deletions

View File

@@ -29,11 +29,6 @@ static inline char *copyString(const char *s)
void Rktwebview_qt::processCommand(Command *cmd)
{
switch(cmd->cmd) {
case COMMAND_QUIT: {
_app->quit();
cmd->done = true;
}
break;
case COMMAND_CREATE: {
rkt_wv_context_t context = cmd->args[0].toInt();
rktwebview_t parent = cmd->args[1].toInt();
@@ -80,6 +75,11 @@ void Rktwebview_qt::processCommand(Command *cmd)
_views.remove(wv);
w->closeView();
cmd->result = true;
while(w->isVisible()) {
doEvents();
}
_view_js_callbacks.remove(wv);
delete w;
} else {
cmd->result = false;
}
@@ -630,7 +630,7 @@ result_t Rktwebview_qt::fileDlg(rktwebview_t w, const char *title, const char *b
QStringList l = dlg->selectedFiles();
QString file;
if (l.size() > 0) {
file = dlg->selectedFiles().first();
file = l[0];
}
EventContainer e(evt_ok);
@@ -817,19 +817,41 @@ void Rktwebview_qt::triggerEvent(rktwebview_t wv, const QString &msg)
}
}
void Rktwebview_qt::rktQuit()
void Rktwebview_qt::execApp()
{
QList<int> keys = _views.keys();
int i;
for(i = 0; i < keys.size(); i++) {
int view_handle = keys[i];
rktWebViewClose(view_handle);
}
_app->exec();
}
QApplication *Rktwebview_qt::app()
{
return _app;
}
void Rktwebview_qt::deleteApp()
{
delete _app;
_app = nullptr;
}
void Rktwebview_qt::initApp()
{
_app = new QApplication(_argc, _argv);
// See Qt 6.10 remark at doEvents.
//connect(&_evt_loop_timer, &QTimer::timeout, this, &Rktwebview_qt::stopEventloop);
// Because we are using processEvents only (Qt 6.10), we need this dispatcher to
// handle deferred Deletes.
const auto *eventDispatcher = QThread::currentThread()->eventDispatcher();
QObject::connect(eventDispatcher, &QAbstractEventDispatcher::aboutToBlock,
QThread::currentThread(), []{
if (QThread::currentThread()->loopLevel() == 0)
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
}
);
Command c(COMMAND_QUIT);
postCommand(&c);
while(!c.done) { doEvents(); }
}
void Rktwebview_qt::runJs(rktwebview_t wv, const char *js)
@@ -889,35 +911,17 @@ void Rktwebview_qt::stopEventloop()
}
Rktwebview_qt::Rktwebview_qt(Rktwebview_qt **handler) :
QObject()
Rktwebview_qt::Rktwebview_qt() : QObject()
{
_argc = 1;
_argv[0] = const_cast<char *>("Rktwebview_qt");
_context_counter = 0;
_current_handle = 0;
_handler = handler;
_evt_loop_depth = 0;
_app = new QApplication(_argc, _argv);
// See Qt 6.10 remark at doEvents.
//connect(&_evt_loop_timer, &QTimer::timeout, this, &Rktwebview_qt::stopEventloop);
// Because we are using processEvents only (Qt 6.10), we need this dispatcher to
// handle deferred Deletes.
const auto *eventDispatcher = QThread::currentThread()->eventDispatcher();
QObject::connect(eventDispatcher, &QAbstractEventDispatcher::aboutToBlock,
QThread::currentThread(), []{
if (QThread::currentThread()->loopLevel() == 0)
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
}
);
*_handler = nullptr;
_app = nullptr;
}
Rktwebview_qt::~Rktwebview_qt()
@@ -934,4 +938,6 @@ Rktwebview_qt::~Rktwebview_qt()
QWebEngineProfile *p = _contexts[c_keys[i]];
delete p;
}
delete _app;
}