#include "mainwindow.h"#include <QApplication>#include <QtWebEngineCore>#include <QtWebEngineWidgets>#include <QUrl>#include <QString>int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; QString token; QString id; w.show(); return a.exec();}
#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include "string.h"#include "vkapiwin.h"namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECTpublic: explicit MainWindow(QWidget *parent = 0); ~MainWindow();private slots: void on_pushButton_2_clicked(); void on_pushButton_clicked();private: Ui::MainWindow *ui; vkapiwin *vkapi;};#endif // MAINWINDOW_H
#ifndef VKAPIWIN_H#define VKAPIWIN_H#include <QWidget>namespace Ui {class vkapiwin;}class vkapiwin : public QWidget{ Q_OBJECTpublic: explicit vkapiwin(QWidget *parent = 0); ~vkapiwin(); Ui::vkapiwin *ui;public slots: virtual void check_url(QUrl &url,QString &token,QString &id);};#endif // VKAPIWIN_H
#include "mainwindow.h"#include "ui_mainwindow.h"#include "vkapiwin.h"#include <QUrlQuery>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this);}MainWindow::~MainWindow(){ delete ui;}void MainWindow::on_pushButton_2_clicked(){ vkapiwin *vkapi= new vkapiwin(); vkapi->show(); if (vkapi == NULL) { vkapi->hide(); this->show(); }}void MainWindow::on_pushButton_clicked(){ ............}
#include "vkapiwin.h"#include "ui_vkapiwin.h"#include <QUrlQuery>#include <QSsl>#include <QWidget>vkapiwin::vkapiwin(QWidget *parent) : QWidget(parent), ui(new Ui::vkapiwin){ ui->setupUi(this); ui->preview->load(QUrl("https://oauth.vk.com/authorize?client_id=5681259&display=mobile&redirect_uri=https://oauth.vk.com/blank.html&scope=friends&response_type=token&v=5.60&state=123456")); connect(ui->preview,SIGNAL(urlChanged(QUrl)),this,SLOT(check_url(QUrl,token,id))); ui->preview->show();}vkapiwin::~vkapiwin(){ delete ui;}void vkapiwin::check_url(QUrl &url,QString &token,QString &id){ url = url.toString().replace("#","?"); token = QUrlQuery(url).queryItemValue("access_token"); id = QUrlQuery(url).queryItemValue("user_id");}
C++ (Qt)connect(ui->preview,SIGNAL(urlChanged(QUrl)),this,SLOT(check_url(QUrl,QString,QString)));
C++ (Qt)connect(ui->preview,SIGNAL(urlChanged(QUrl)),this,SLOT(check_url(QUrl))); и void vkapiwin::check_url(QUrl url) { url = url.toString().replace("#","?"); this->token = QUrlQuery(url).queryItemValue("access_token"); this->id = QUrlQuery(url).queryItemValue("user_id");}
void vkapiwin::check_url(QUrl &url){ QString url1 = url.toString().replace("#","?"); this->token = QUrlQuery(url1).queryItemValue("access_token"); this->id = QUrlQuery(url1).queryItemValue("user_id");}
C++ (Qt)#include <QtCore>#include <QtGui>#include <QtWidgets>#include <QWebEngineView> class A : public QObject{ Q_OBJECT public slots: void printUrl(const QUrl &url) { qDebug() << "from A:" << url; }}; int main(int argc, char *argv[]){ QApplication app(argc, argv); QWebEngineView w; A a; QObject::connect(&w, SIGNAL(urlChanged(QUrl)), &a, SLOT(printUrl(QUrl))); QObject::connect(&w, &QWebEngineView::urlChanged, [](const QUrl &url){ qDebug() << "from lambda:" << url; }); w.load(QUrl("https://oauth.vk.com/authorize?client_id=5681259&display=mobile&redirect_uri=https://oauth.vk.com/blank.html&scope=friends&response_type=token&v=5.60&state=123456")); w.show(); return app.exec();} #include "main.moc"