Embed a QWebEngineView process inside QTabWidget



  • I'm trying to integrate a QWebEngineView widget that runs as a separate process(QProcess) inside a QTabWidget page. So far the QWebEngineView process is being started properly but its showing the webpage in a separate window instead of showing it inside the QTabWidget in the MainWindow application.

    This is the Widget that is being added to the QTabWidget.

    BrokersTerminal.h
    
    class BrokersTerminal : public QWidget
    {
        Q_OBJECT
    
      public:
        explicit BrokersTerminal(QWidget *parent = 0);
        ~BrokersTerminal();
    
        void startTerminal();
    
      public slots:
        void brokersTerminalStarted();
    
      private:
        Ui::BrokersTerminal *ui;
        QProcess *brokers_process;
        QString brokers_program_path;
        QStringList arguments;
    };
    
    
    BrokersTerminal.cpp
    
    BrokersTerminal::BrokersTerminal(QWidget *parent) :
      QWidget(parent),
      ui(new Ui::BrokersTerminal)
    {
      ui->setupUi(this);
      brokers_process = new QProcess( this );
      brokers_program_path = QApplication::applicationFilePath();
    
      arguments << "--b";
    
      connect( brokers_process, &QProcess::started, this , &BrokersTerminal::brokersTerminalStarted );
    }
    
    BrokersTerminal::~BrokersTerminal()
    {
      delete ui;
    }
    
    void BrokersTerminal::startTerminal()
    {
      brokers_process->start( brokers_program_path, arguments );
      brokers_process->waitForStarted();
    }
    
    void BrokersTerminal::brokersTerminalStarted()
    {
      qDebug() << "Brokers terminal started";
    }
    

    This is the WebView Widget that is responsible for displaying the brokers website.

    BrokersWebWidget.h
    
    class BrokersWebWidget : public QWidget
    {
        Q_OBJECT
    
      public:
        explicit BrokersWebWidget(QWidget *parent = 0);
        ~BrokersWebWidget();
    
      private:
        Ui::BrokersWebWidget *ui;
        QUrl brokers_url;
        QWebEngineView *web_browser;
    };
    
    BrokersWebWidget.cpp
    
    BrokersWebWidget::BrokersWebWidget(QWidget *parent) :
      QWidget(parent),
      ui(new Ui::BrokersWebWidget)
    {
      ui->setupUi(this);
    
      brokers_url = "https://siteofbrokersapi.com/";
    
      web_browser = new QWebEngineView( this );
      web_browser->load( brokers_url );
    }
    
    BrokersWebWidget::~BrokersWebWidget()
    {
      delete ui;
    }
    

    Right now this BrokersWebWidget starts properly as a separate process but it opens in a separate window , but how can this be added in the BrokersTerminal Widget ?

    Please let me know of any possible solutions. Thanks.


  • Moderators

    One possible solution would be to use shared memory and put the QWebEngineView into this memory to be able to access it in both processes. But I have no idea whether this will cause any issues with Qt GUI. Most probably it will, because Qt GUI classes are NOT thread save and you will access it from two different processes at the same time!
    I still don't understand why you want to put QWebEngineView in another process. Even if it is possible you will add a huge amount of complexity without any advantages (at least I do not see any).



  • @jsulm said:

    One possible solution would be to use shared memory and put the QWebEngineView into this memory to be able to access it in both processes. But I have no idea whether this will cause any issues with Qt GUI. Most probably it will, because Qt GUI classes are NOT thread save and you will access it from two different processes at the same time!
    I still don't understand why you want to put QWebEngineView in another process. Even if it is possible you will add a huge amount of complexity without any advantages (at least I do not see any).

    Well i was under the impression that the QWebEngineView process is a heavy weight process that might freeze the Main GUI so i had the idea of putting it in a separate process. But you're right this will bring up much unnecessary complexity. So i have changed the whole design plan and the approach. What i will do instead is to keep all the GUI windows, widgets in the same MainWindow process, but run the heavy computations as a background process. Anyways thanks for your advice , really appreciate it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.