How to run a plugin with WebEngine or WebView?

YuryK

New Member
Hello! I am very new to C++. I am building a plugin in C++ that should have a web view as part of it's functionality. I was able to build the plugin, but it is not loading properly in OBS studio.

If I remove QWebEngineView initialization, the plugin is loading as expected.

I am attaching the main plugin code, cmakelists, OBS logs and windbg logs. Plugin name is awerty.

I've read all the related topics here on the forum and in general. It is still hard to understand for me why the building process went fine, but the plugin will not run. Please let me know if you have any suggestions how to fix that.

C++:
//plugin-main.cpp
#include <obs-module.h>
#include <plugin-support.h>
#include <obs-frontend-api.h>
#include <obs.hpp>
#include <obs.h>

#include <QDockWidget>
#include <QMainWindow>
#include <QVBoxLayout>
#include <QWebEngineView>

OBS_DECLARE_MODULE()
OBS_MODULE_USE_DEFAULT_LOCALE(PLUGIN_NAME, "en-US")

class CustomDockWidget : public QDockWidget
{
public:
    CustomDockWidget(QWidget *parent = nullptr) : QDockWidget(parent)
    {
        obs_log(LOG_INFO, "Creating CustomDockWidget");
        QWidget *content = new QWidget(this);
        QVBoxLayout *layout = new QVBoxLayout(content);
       
        // THIS LINE BREAKS THE PLUGIN!
        QWebEngineView *webView = new QWebEngineView(content);
       
       
        // webView->load(QUrl("https://google.com"));

        // layout->addWidget(webView);
        setWidget(content);
        obs_log(LOG_INFO, "CustomDockWidget created successfully");
    }
};

bool obs_module_load(void)
{
    obs_log(LOG_INFO, "plugin loaded successfully (version %s)", PLUGIN_VERSION);

    obs_log(LOG_INFO, "Getting main window");
    const auto main_window =
        static_cast<QMainWindow *>(obs_frontend_get_main_window());

    obs_log(LOG_INFO, "Creating CustomDockWidget");
    CustomDockWidget *dockWidget = new CustomDockWidget(main_window);

    obs_log(LOG_INFO, "Setting up dock widget properties");
    dockWidget->setObjectName(QStringLiteral("statsDock"));
    dockWidget->setFeatures(QDockWidget::DockWidgetClosable |
                   QDockWidget::DockWidgetMovable |
                   QDockWidget::DockWidgetFloatable);

    obs_log(LOG_INFO, "Adding dock widget to main window");
    main_window->addDockWidget(Qt::BottomDockWidgetArea, dockWidget);
    dockWidget->setVisible(false);
    dockWidget->setFloating(true);
    dockWidget->resize(700, 200);

    obs_log(LOG_INFO, "Adding dock to OBS frontend");
    obs_frontend_add_dock_by_id("awerty", "awerty", dockWidget);

    obs_log(LOG_INFO, "Plugin load completed successfully");
    return true;
}

void obs_module_unload(void)
{
    obs_log(LOG_INFO, "plugin unloaded");
}
 

Attachments

  • CMakeLists.txt
    1.6 KB · Views: 9
  • OBS logs.txt
    9.1 KB · Views: 10
  • windbg logs.txt
    37.5 KB · Views: 5
  • build logs.txt
    2.3 KB · Views: 10
Top