Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Embed a QWebEngineView process inside QTabWidget
Forum Updated to NodeBB v4.3 + New Features

Embed a QWebEngineView process inside QTabWidget

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maxx Dovahkiin
    wrote on last edited by Maxx Dovahkiin
    #1

    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.

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      1
      • jsulmJ jsulm

        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).

        M Offline
        M Offline
        Maxx Dovahkiin
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved