Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. how to obtain link from (right click + open in new tab) .
Forum Updated to NodeBB v4.3 + New Features

how to obtain link from (right click + open in new tab) .

Scheduled Pinned Locked Moved Solved QtWebEngine
6 Posts 3 Posters 2.3k Views
  • 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.
  • AnmolA Offline
    AnmolA Offline
    Anmol
    wrote on last edited by
    #1

    i am new to Qt and i am working on a project which uses Qwebengine.

    alt text

    i cant open this file because its opening in new tab but my project have not have Qtab object . my project have to open every link in current window.

    how can in get new tab url so i can change it with current url and open new tab page in current tab?

    KillerSmathK 1 Reply Last reply
    0
    • AnmolA Anmol

      i am new to Qt and i am working on a project which uses Qwebengine.

      alt text

      i cant open this file because its opening in new tab but my project have not have Qtab object . my project have to open every link in current window.

      how can in get new tab url so i can change it with current url and open new tab page in current tab?

      KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by
      #2

      @Anmol
      I hope this topic can help you.
      https://stackoverflow.com/questions/6636757/qwebpage-force-to-open-link-in-same-tab/22290289#22290289

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      AnmolA 1 Reply Last reply
      0
      • KillerSmathK KillerSmath

        @Anmol
        I hope this topic can help you.
        https://stackoverflow.com/questions/6636757/qwebpage-force-to-open-link-in-same-tab/22290289#22290289

        AnmolA Offline
        AnmolA Offline
        Anmol
        wrote on last edited by
        #3

        @KillerSmath thank for your help but im using Webengine and that topic was for webkit.
        still i dont know how to solve it.

        JonBJ 1 Reply Last reply
        0
        • AnmolA Anmol

          @KillerSmath thank for your help but im using Webengine and that topic was for webkit.
          still i dont know how to solve it.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Anmol
          I think you can achieve this via https://doc.qt.io/qt-5/qwebengineview.html#createWindow, or https://doc.qt.io/qt-5/qwebenginepage.html#createWindow. At least look into these to see if you can force same window? Or, you may have to read & digest https://stackoverflow.com/questions/40170180/link-clicked-signal-qwebengineview. Or you may want to look at https://www.qtcentre.org/threads/62740-Issue-with-loading-the-link-clicked-page-in-new-tab, which faces the same situation but resolves by creating its own tab.

          Ah, I think https://stackoverflow.com/questions/47893838/make-any-link-even-blank-open-in-same-window-using-qwebengine is exactly what you want. Achieved by overriding QWebEngineView::createWindow() to return self/this as I hoped would work....

          AnmolA 2 Replies Last reply
          1
          • JonBJ JonB

            @Anmol
            I think you can achieve this via https://doc.qt.io/qt-5/qwebengineview.html#createWindow, or https://doc.qt.io/qt-5/qwebenginepage.html#createWindow. At least look into these to see if you can force same window? Or, you may have to read & digest https://stackoverflow.com/questions/40170180/link-clicked-signal-qwebengineview. Or you may want to look at https://www.qtcentre.org/threads/62740-Issue-with-loading-the-link-clicked-page-in-new-tab, which faces the same situation but resolves by creating its own tab.

            Ah, I think https://stackoverflow.com/questions/47893838/make-any-link-even-blank-open-in-same-window-using-qwebengine is exactly what you want. Achieved by overriding QWebEngineView::createWindow() to return self/this as I hoped would work....

            AnmolA Offline
            AnmolA Offline
            Anmol
            wrote on last edited by Anmol
            #5

            @JonB thanks for your help .its working
            but only i choose "open i new window" from context menu(right click menu)

            if i click on link which open in new tab by default
            its gives me this error
            0_1559376447109_Screenshot (92).png

            to go on next page i have to click on ignore button.(in release build its get crash with out warning .

            my code :

            ---------------------------------------------------------------------------*

            main.cpp

            #include "linkclick.h"
            #include <QApplication>
            
            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
                linkClick w;
                w.show();
            
                return a.exec();
            }
            

            ---------------------------------------------------------------------------*
            linkclick.h

            #ifndef LINKCLICK_H
            #define LINKCLICK_H
            
            #include <QMainWindow>
            #include<webpage.h>
            #include <QWebEngineView>
            #include <QWebEngineProfile>
            
            namespace Ui {
            class linkClick;
            }
            
            class linkClick : public QMainWindow
            {
                Q_OBJECT
            
            public:
                explicit linkClick(QWidget *parent = nullptr);
                ~linkClick();
                void paintEvent(QPaintEvent *event);
            
            private:
                Ui::linkClick *ui;
                webpage *page;
                QWebEngineView *web;
            };
            
            #endif // LINKCLICK_H
            

            ---------------------------------------------------------------------------*

            linkclick.cpp

            #include "linkclick.h"
            #include "ui_linkclick.h"
            
            linkClick::linkClick(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::linkClick)
            {
                ui->setupUi(this);
                QWebEngineProfile::defaultProfile()->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
                web = new QWebEngineView(ui->centralWidget);
                page = new webpage();
                page->setUrl(QUrl("https://office.live.com/start/excel.aspx"));
            
                web->setPage(page);
                web->show();
            }
            
            linkClick::~linkClick()
            {
                delete ui;
            }
            
            void linkClick::paintEvent(QPaintEvent *event)
            {
                QMainWindow::paintEvent(event);
                web->resize(ui->centralWidget->size());
            }
            
            

            ---------------------------------------------------------------------------*
            webpage.h

            #ifndef WEBPAGE_H
            #define WEBPAGE_H
            
            #include <QWebEngineView>
            
            class webpage :public QWebEnginePage
            {
            public:
                webpage();
                QWebEnginePage* createWindow(QWebEnginePage::WebWindowType type);
                QWebEngineView t;
            };
            
            #endif // WEBPAGE_H
            

            ---------------------------------------------------------------------------*
            webpage.cpp

            #include "webpage.h"
            webpage::webpage()
            {
            
            }
            
            QWebEnginePage *webpage::createWindow(QWebEnginePage::WebWindowType type)
            {
                if(type == QWebEnginePage::WebBrowserTab)
                    return this;
            }
            

            ---------------------------------------------------------------------------*

            1 Reply Last reply
            0
            • JonBJ JonB

              @Anmol
              I think you can achieve this via https://doc.qt.io/qt-5/qwebengineview.html#createWindow, or https://doc.qt.io/qt-5/qwebenginepage.html#createWindow. At least look into these to see if you can force same window? Or, you may have to read & digest https://stackoverflow.com/questions/40170180/link-clicked-signal-qwebengineview. Or you may want to look at https://www.qtcentre.org/threads/62740-Issue-with-loading-the-link-clicked-page-in-new-tab, which faces the same situation but resolves by creating its own tab.

              Ah, I think https://stackoverflow.com/questions/47893838/make-any-link-even-blank-open-in-same-window-using-qwebengine is exactly what you want. Achieved by overriding QWebEngineView::createWindow() to return self/this as I hoped would work....

              AnmolA Offline
              AnmolA Offline
              Anmol
              wrote on last edited by Anmol
              #6

              @JonB my problem is solve before "return this;" just have to set a page to this(QWebEngineview)

              0_1559472452638_Screenshot (101).png

              just write this line and problem solve.

              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