Skip to content

Commit 6cb9020

Browse files
author
Alexis Lopez Zubieta
committed
Add QtWebEngineApplication example
1 parent daac6e0 commit 6cb9020

File tree

7 files changed

+164
-9
lines changed

7 files changed

+164
-9
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Desktop Entry]
2+
Version=1.0
3+
Type=Application
4+
Name=Qt Web Engine Application
5+
Exec=QtWebEngineApplication
6+
TryExec=QtWebEngineApplication
7+
Icon=QtWebEngineApplication
8+
Categories=Development;
18.5 KB
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
TEMPLATE = app
2+
3+
QT += webengine
4+
5+
SOURCES += main.cpp
6+
7+
RESOURCES += qml.qrc
8+
9+
target.path = $$PREFIX/bin
10+
icon.path = $$PREFIX/share/icons/hicolor/512x512
11+
icon.files = QtWebEngineApplication.png
12+
13+
desktop_entry.path = $$PREFIX/share/applications
14+
desktop_entry.files = QtWebEngineApplication.desktop
15+
INSTALLS += target icon desktop_entry

QtWebEngineApplication/main.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2016-18 The Qt Company Ltd.
4+
** Contact: http://www.qt.io/licensing/
5+
**
6+
** This file is part of the examples of the Qt Toolkit.
7+
**
8+
** $QT_BEGIN_LICENSE:BSD$
9+
** You may use this file under the terms of the BSD license as follows:
10+
**
11+
** "Redistribution and use in source and binary forms, with or without
12+
** modification, are permitted provided that the following conditions are
13+
** met:
14+
** * Redistributions of source code must retain the above copyright
15+
** notice, this list of conditions and the following disclaimer.
16+
** * Redistributions in binary form must reproduce the above copyright
17+
** notice, this list of conditions and the following disclaimer in
18+
** the documentation and/or other materials provided with the
19+
** distribution.
20+
** * Neither the name of The Qt Company Ltd nor the names of its
21+
** contributors may be used to endorse or promote products derived
22+
** from this software without specific prior written permission.
23+
**
24+
**
25+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26+
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27+
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28+
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29+
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30+
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31+
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32+
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33+
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36+
**
37+
** $QT_END_LICENSE$
38+
**
39+
****************************************************************************/
40+
41+
#include <QGuiApplication>
42+
#include <QQmlApplicationEngine>
43+
#include <qtwebengineglobal.h>
44+
45+
int main(int argc, char *argv[])
46+
{
47+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
48+
QGuiApplication app(argc, argv);
49+
50+
QtWebEngine::initialize();
51+
52+
QQmlApplicationEngine engine;
53+
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
54+
55+
return app.exec();
56+
}

QtWebEngineApplication/main.qml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/****************************************************************************
2+
**
3+
** Copyright (C) 2016-18 The Qt Company Ltd.
4+
** Contact: http://www.qt.io/licensing/
5+
**
6+
** This file is part of the examples of the Qt Toolkit.
7+
**
8+
** $QT_BEGIN_LICENSE:BSD$
9+
** You may use this file under the terms of the BSD license as follows:
10+
**
11+
** "Redistribution and use in source and binary forms, with or without
12+
** modification, are permitted provided that the following conditions are
13+
** met:
14+
** * Redistributions of source code must retain the above copyright
15+
** notice, this list of conditions and the following disclaimer.
16+
** * Redistributions in binary form must reproduce the above copyright
17+
** notice, this list of conditions and the following disclaimer in
18+
** the documentation and/or other materials provided with the
19+
** distribution.
20+
** * Neither the name of The Qt Company Ltd nor the names of its
21+
** contributors may be used to endorse or promote products derived
22+
** from this software without specific prior written permission.
23+
**
24+
**
25+
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26+
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27+
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28+
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29+
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30+
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31+
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32+
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33+
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34+
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35+
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36+
**
37+
** $QT_END_LICENSE$
38+
**
39+
****************************************************************************/
40+
41+
import QtQuick 2.0
42+
import QtQuick.Window 2.0
43+
import QtWebEngine 1.0
44+
45+
Window {
46+
width: 1024
47+
height: 750
48+
visible: true
49+
WebEngineView {
50+
anchors.fill: parent
51+
url: "http://www.qt.io"
52+
}
53+
}

QtWebEngineApplication/qml.qrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
</qresource>
5+
</RCC>

build_appimages.sh

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ BASE_DIR=${PWD}
66
mkdir ${BASE_DIR}/out
77

88
# Download tools
9-
wget -N https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-"$ARCH".AppImage
10-
chmod +x linuxdeploy-"$ARCH".AppImage
9+
#wget -N https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-"$ARCH".AppImage
10+
#chmod +x linuxdeploy-"$ARCH".AppImage
1111

12-
wget -N https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-"$ARCH".AppImage
13-
chmod +x linuxdeploy-plugin-qt-"$ARCH".AppImage
12+
#wget -N https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-"$ARCH".AppImage
13+
#chmod +x linuxdeploy-plugin-qt-"$ARCH".AppImage
1414

1515
LINUXDEPLOY_BIN=${PWD}/linuxdeploy-"$ARCH".AppImage
1616
LINUXDEPLOY_PLUGIN_QT_BIN=${PWD}/linuxdeploy-plugin-qt-"$ARCH".AppImage
@@ -25,18 +25,36 @@ build_appimage() {
2525
${LINUXDEPLOY_PLUGIN_QT_BIN} --appdir ${APP_DIR} || return 1
2626
${LINUXDEPLOY_BIN} --app-name ${APP_NAME} --appdir ${APP_DIR} --output appimage || return 1
2727

28-
mv *.AppImage ${BASE_DIR}/out || return 1
28+
mv -v *AppImage ${BASE_DIR}/out || return 1
2929
}
3030

31-
# Build projects
31+
Build projects
3232
pushd QtQuickControls2Application
33+
# This env variable is used by the qt plugin to search the qml sources in other paths than the AppDir
34+
# it's mandatory to use when your qml files are embed as Qt resources into the main binary.
3335
export QML_SOURCES_PATHS="${PWD}/src"
3436

37+
# This env variable is used by the qt plugin to search the qml modules in other paths than the default
38+
# Qt qml dir.
39+
export QML_MODULES_PATHS=""
40+
41+
mkdir build
42+
pushd build
43+
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr || exit 1
44+
DESTDIR=AppDir make install || exit 1
45+
46+
build_appimage QtQuickControls2Application ${PWD}/AppDir || exit 1
47+
popd
48+
popd
49+
50+
pushd QtWebEngineApplication
51+
export QML_SOURCES_PATHS="${PWD}"
52+
3553
mkdir build
3654
pushd build
37-
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr
38-
DESTDIR=AppDir make install
55+
qmake CONFIG+=release PREFIX=/usr ../QtWebEngineApplication.pro || exit 1
56+
INSTALL_ROOT=${PWD}/AppDir make install || exit 1
3957

40-
build_appimage QtQuickControls2Application ${PWD}/AppDir
58+
build_appimage QtWebEngineApplication ${PWD}/AppDir || exit 1
4159
popd
4260
popd

0 commit comments

Comments
 (0)