Ubuntu +QT+webenginewidgets 跨平台嵌入web程序

作者: shaoliang 2020-04-12 06:48   访问数:841

Ubuntu +QT+webenginewidgets 跨平台嵌入web程序


QT       += core gui webenginewidgets
QMAKE_LFLAGS += -no-pie
#-------------------------------------------------
#
# Project created by QtCreator 2020-04-09T19:56:40
#
#-------------------------------------------------

QT       += core gui
QT       += core gui webenginewidgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = 51dr
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0


SOURCES += \
        main.cpp \
        dialog.cpp

HEADERS += \
        dialog.h

FORMS += \
        dialog.ui

QMAKE_LFLAGS += -no-pie



头文件

#ifndef DIALOG_H
#define DIALOG_H



#include 《QDialog》
#include 《qwebengineview.h》

namespace Ui {
class Dialog;
}

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

private slots:

    void on_btn_OpenWeb_clicked();
    void on_btn_OpenManage_clicked();
private:
    Ui::Dialog *ui;
    QWebEngineView *webview1;
    QWebEngineView *v2;

};

#endif // DIALOG_H



CPP 文件

#include "dialog.h"
#include "ui_dialog.h"
#include 《QScreen》

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);

    //    QTime t;
    //    t.start();
    //    while(t.elapsed()setWindowFlags(Qt::Dialog | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
    //    showFullScreen();
    //    showMaximized();

    QScreen *screen=QGuiApplication::primaryScreen ();
    QRect mm=screen->availableGeometry() ;

    this->resize(mm.width(),mm.height());
    ui->tabWidget->setCurrentIndex(0);

    webview1=new QWebEngineView(ui->tab1);
    webview1->resize(this->size());
    webview1->setUrl(QUrl("https://51dr.top"));
    webview1->show();
}

Dialog::~Dialog()
{
    delete webview1;
    delete ui;
}


void Dialog::on_btn_OpenWeb_clicked()
{

    ui->tabWidget->setCurrentIndex(0);

    webview1=new QWebEngineView(ui->tab1);
    webview1->resize(ui->tab1->size());
    webview1->setUrl(QUrl("https://51dr.top"));
    webview1->show();
}

void Dialog::on_btn_OpenManage_clicked()
{
    ui->tabWidget->setCurrentIndex(1);
    webview1=new QWebEngineView(ui->tab2);
    webview1->resize(ui->tab2->size());
    webview1->setUrl(QUrl("https://51dr.top/admin/user/"));
    webview1->show();
}


void Dialog::on_btn_addarticle_clicked()
{
    ui->tabWidget->setCurrentIndex(1);
    webview1=new QWebEngineView(ui->tab2);
    webview1->resize(ui->tab2->size());
    webview1->setUrl(QUrl("https://51dr.top/admin/article/insert/"));
    webview1->show();
}



2020-04-10 22-44-23 的屏幕截图.png


q3200410.tar.gz



51drwebengine200411-2.tar.gz

下载修改扩展名为 tar.gz

鲁ICP备19029146号-1 管理
CopyRight@51dr.top 页面打开时间 0.0310 秒.