how to obtain link from (right click + open in new tab) .
-
i am new to Qt and i am working on a project which uses Qwebengine.
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?
-
@Anmol
I hope this topic can help you.
https://stackoverflow.com/questions/6636757/qwebpage-force-to-open-link-in-same-tab/22290289#22290289 -
@KillerSmath thank for your help but im using Webengine and that topic was for webkit.
still i dont know how to solve it. -
@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 returnself
/this
as I hoped would work.... -
@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
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; }
---------------------------------------------------------------------------*