summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@gmail.com>2016-09-03 13:58:38 +0200
committerPaul Olav Tvete <paul.tvete@qt.io>2016-09-08 13:26:35 +0000
commit004c6ffdbdb91f215364740a1975b37fe54b757c (patch)
tree5284348819486de178c51209f95482e10847c1c5 /examples
parent7310fd4c925df7a3de0ae63e44ba0627228adc84 (diff)
Simplify custom-extension example
Don't confuse people by creating the extension inside a platform plugin. It's only necessary when modifying Qt's default behaviour, and we're not going to teach that in this example. Also remove the load/unload extension logic from the qml example. Don't make people believe that they have to use a loader. Change-Id: Id263bb7d77fba176bfb8b6843a6ece9a0a203754 Reviewed-by: Johan Helsing <johan.helsing@qt.io> Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@hawaiios.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/wayland/custom-extension/client-common/.gitignore (renamed from examples/wayland/custom-extension/client/.gitignore)0
-rw-r--r--examples/wayland/custom-extension/client-common/client.json (renamed from examples/wayland/custom-extension/client/client.json)0
-rw-r--r--examples/wayland/custom-extension/client-common/client.pro (renamed from examples/wayland/custom-extension/client/client.pro)0
-rw-r--r--examples/wayland/custom-extension/client-common/customextension.cpp (renamed from examples/wayland/custom-extension/client/customextension.cpp)0
-rw-r--r--examples/wayland/custom-extension/client-common/customextension.h (renamed from examples/wayland/custom-extension/client/customextension.h)0
-rw-r--r--examples/wayland/custom-extension/client-common/main.cpp (renamed from examples/wayland/custom-extension/client/main.cpp)0
-rw-r--r--examples/wayland/custom-extension/cpp-client/.gitignore3
-rw-r--r--examples/wayland/custom-extension/cpp-client/cpp-client.pro22
-rw-r--r--examples/wayland/custom-extension/cpp-client/main.cpp (renamed from examples/wayland/custom-extension/testapp/main.cpp)26
-rw-r--r--examples/wayland/custom-extension/custom-extension.pro7
-rw-r--r--examples/wayland/custom-extension/qml-client/.gitignore3
-rw-r--r--examples/wayland/custom-extension/qml-client/main.cpp (renamed from examples/wayland/custom-extension/qmltestapp/main.cpp)2
-rw-r--r--examples/wayland/custom-extension/qml-client/main.qml (renamed from examples/wayland/custom-extension/qmltestapp/main.qml)45
-rw-r--r--examples/wayland/custom-extension/qml-client/qml-client.pro (renamed from examples/wayland/custom-extension/qmltestapp/qmltestapp.pro)6
-rw-r--r--examples/wayland/custom-extension/qml-client/qml.qrc (renamed from examples/wayland/custom-extension/qmltestapp/qml.qrc)0
-rw-r--r--examples/wayland/custom-extension/testapp/testapp.pro6
16 files changed, 50 insertions, 70 deletions
diff --git a/examples/wayland/custom-extension/client/.gitignore b/examples/wayland/custom-extension/client-common/.gitignore
index b4961e189..b4961e189 100644
--- a/examples/wayland/custom-extension/client/.gitignore
+++ b/examples/wayland/custom-extension/client-common/.gitignore
diff --git a/examples/wayland/custom-extension/client/client.json b/examples/wayland/custom-extension/client-common/client.json
index 7aab544e5..7aab544e5 100644
--- a/examples/wayland/custom-extension/client/client.json
+++ b/examples/wayland/custom-extension/client-common/client.json
diff --git a/examples/wayland/custom-extension/client/client.pro b/examples/wayland/custom-extension/client-common/client.pro
index 9ba72bc9c..9ba72bc9c 100644
--- a/examples/wayland/custom-extension/client/client.pro
+++ b/examples/wayland/custom-extension/client-common/client.pro
diff --git a/examples/wayland/custom-extension/client/customextension.cpp b/examples/wayland/custom-extension/client-common/customextension.cpp
index 050b0d5c2..050b0d5c2 100644
--- a/examples/wayland/custom-extension/client/customextension.cpp
+++ b/examples/wayland/custom-extension/client-common/customextension.cpp
diff --git a/examples/wayland/custom-extension/client/customextension.h b/examples/wayland/custom-extension/client-common/customextension.h
index a041d5a7e..a041d5a7e 100644
--- a/examples/wayland/custom-extension/client/customextension.h
+++ b/examples/wayland/custom-extension/client-common/customextension.h
diff --git a/examples/wayland/custom-extension/client/main.cpp b/examples/wayland/custom-extension/client-common/main.cpp
index 8c27fa77d..8c27fa77d 100644
--- a/examples/wayland/custom-extension/client/main.cpp
+++ b/examples/wayland/custom-extension/client-common/main.cpp
diff --git a/examples/wayland/custom-extension/cpp-client/.gitignore b/examples/wayland/custom-extension/cpp-client/.gitignore
new file mode 100644
index 000000000..b191089e5
--- /dev/null
+++ b/examples/wayland/custom-extension/cpp-client/.gitignore
@@ -0,0 +1,3 @@
+cpp-client
+qwayland-custom.cpp
+qwayland-custom.h
diff --git a/examples/wayland/custom-extension/cpp-client/cpp-client.pro b/examples/wayland/custom-extension/cpp-client/cpp-client.pro
new file mode 100644
index 000000000..9636d1101
--- /dev/null
+++ b/examples/wayland/custom-extension/cpp-client/cpp-client.pro
@@ -0,0 +1,22 @@
+QT += waylandclient-private
+
+CONFIG += c++11
+CONFIG += wayland-scanner
+CONFIG += link_pkgconfig
+
+WAYLANDCLIENTSOURCES += ../protocol/custom.xml
+
+!contains(QT_CONFIG, no-pkg-config) {
+ PKGCONFIG += wayland-client
+} else {
+ LIBS += -lwayland-client
+}
+
+SOURCES += main.cpp \
+ ../client-common/customextension.cpp
+
+HEADERS += \
+ ../client-common/customextension.h
+
+target.path = $$[QT_INSTALL_EXAMPLES]/wayland/custom-extension/cpp-client
+INSTALLS += target
diff --git a/examples/wayland/custom-extension/testapp/main.cpp b/examples/wayland/custom-extension/cpp-client/main.cpp
index 59738128d..f5894dc81 100644
--- a/examples/wayland/custom-extension/testapp/main.cpp
+++ b/examples/wayland/custom-extension/cpp-client/main.cpp
@@ -42,20 +42,19 @@
#include <QRasterWindow>
#include <QPainter>
#include <QMouseEvent>
+#include "../client-common/customextension.h"
#include <QDebug>
-static QObject *s_custom;
-
class TestWindow : public QRasterWindow
{
Q_OBJECT
public:
- TestWindow()
+ TestWindow(CustomExtension *customExtension)
+ : m_extension(customExtension)
{
- if (s_custom)
- connect(s_custom, SIGNAL(eventReceived(const QString &, uint)),
+ connect(customExtension, SIGNAL(eventReceived(const QString &, uint)),
this, SLOT(handleEvent(const QString &, uint)));
}
@@ -75,7 +74,6 @@ protected:
void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE
{
- Q_ASSERT(s_custom);
bool insideRect = QRect(50,50,100,100).contains(ev->pos());
QString text = insideRect ? "Click inside" : "Click outside";
@@ -83,26 +81,20 @@ protected:
qDebug() << "Client application sending request:" << text << value;
- QMetaObject::invokeMethod(s_custom, "sendRequest", Qt::DirectConnection,
- Q_ARG(QString, text),
- Q_ARG(int, value));
+ m_extension->sendRequest(text, value);
}
private:
-
+ CustomExtension *m_extension;
};
int main (int argc, char **argv)
{
QGuiApplication app(argc, argv);
- s_custom = app.findChild<QObject*>("qt_example_custom_extension");
- if (!s_custom) {
- qCritical() << "This example requires the Qt Custom Extension platform plugin,\n"
- "add -platform custom-wayland to the command line";
- return -1;
- }
- TestWindow window;
+ CustomExtension customExtension;
+
+ TestWindow window(&customExtension);
window.show();
return app.exec();
diff --git a/examples/wayland/custom-extension/custom-extension.pro b/examples/wayland/custom-extension/custom-extension.pro
index 73e1eff7e..ada911349 100644
--- a/examples/wayland/custom-extension/custom-extension.pro
+++ b/examples/wayland/custom-extension/custom-extension.pro
@@ -1,10 +1,7 @@
TEMPLATE=subdirs
-SUBDIRS += client \
- qmltestapp
+SUBDIRS += qml-client
SUBDIRS += compositor
-SUBDIRS += testapp
-
-qmltestapp.depends = client
+SUBDIRS += cpp-client
OTHER_FILES += protocol/custom.xml
diff --git a/examples/wayland/custom-extension/qml-client/.gitignore b/examples/wayland/custom-extension/qml-client/.gitignore
new file mode 100644
index 000000000..18ba6048a
--- /dev/null
+++ b/examples/wayland/custom-extension/qml-client/.gitignore
@@ -0,0 +1,3 @@
+qml-client
+qwayland-custom.cpp
+qwayland-custom.h
diff --git a/examples/wayland/custom-extension/qmltestapp/main.cpp b/examples/wayland/custom-extension/qml-client/main.cpp
index 6140862d9..25814d8cc 100644
--- a/examples/wayland/custom-extension/qmltestapp/main.cpp
+++ b/examples/wayland/custom-extension/qml-client/main.cpp
@@ -43,7 +43,7 @@
#include <QtQml/qqml.h>
#include <QtQml/QQmlEngine>
-#include "../client/customextension.h"
+#include "../client-common/customextension.h"
int main(int argc, char *argv[])
{
diff --git a/examples/wayland/custom-extension/qmltestapp/main.qml b/examples/wayland/custom-extension/qml-client/main.qml
index 10e413efc..c6496b0bf 100644
--- a/examples/wayland/custom-extension/qmltestapp/main.qml
+++ b/examples/wayland/custom-extension/qml-client/main.qml
@@ -53,8 +53,8 @@ Window {
anchors.fill: parent
onClicked: {
console.log("Clicked outside", mouseX)
- if (extensionLoader.item && extensionLoader.item.active)
- extensionLoader.item.sendRequest("Clicked outside", mouseX)
+ if (customExtension.active)
+ customExtension.sendRequest("Clicked outside", mouseX)
}
}
@@ -64,8 +64,8 @@ Window {
onClicked: {
var obj = mapToItem(parent, mouse.x, mouse.y)
console.log("Clicked inside", obj.x)
- if (extensionLoader.item && extensionLoader.item.active)
- extensionLoader.item.sendRequest("Clicked inside", obj.x)
+ if (customExtension.active)
+ customExtension.sendRequest("Clicked inside", obj.x)
}
Rectangle {
@@ -74,40 +74,9 @@ Window {
}
}
- MouseArea {
- anchors.right: parent.right
- anchors.bottom: parent.bottom
- width: 150; height: 25
-
- Rectangle {
- anchors.fill: parent
- color: "#010101"
- Text {
- anchors.centerIn: parent
- color: "white"
- text: extensionLoader.item ? "Unload client extension" : "Load client extension"
- }
- }
- onClicked: {
- extensionLoader.active = !extensionLoader.active
- }
- }
-
- Component {
- id: extensionComponent
- CustomExtension {
- id: customExtension
- onActiveChanged: console.log("Custom extension is active?", active)
- }
- }
-
- Loader {
- id: extensionLoader
- sourceComponent: extensionComponent
- }
-
- Connections {
- target: extensionLoader.item
+ CustomExtension {
+ id: customExtension
+ onActiveChanged: console.log("Custom extension is active:", active)
onEventReceived: console.log("Event received", text, value)
}
}
diff --git a/examples/wayland/custom-extension/qmltestapp/qmltestapp.pro b/examples/wayland/custom-extension/qml-client/qml-client.pro
index 786faeb0b..aec29d2b3 100644
--- a/examples/wayland/custom-extension/qmltestapp/qmltestapp.pro
+++ b/examples/wayland/custom-extension/qml-client/qml-client.pro
@@ -15,14 +15,14 @@ WAYLANDCLIENTSOURCES += ../protocol/custom.xml
}
SOURCES += main.cpp \
- ../client/customextension.cpp
+ ../client-common/customextension.cpp
HEADERS += \
- ../client/customextension.h
+ ../client-common/customextension.h
RESOURCES += qml.qrc
-target.path = $$[QT_INSTALL_EXAMPLES]/wayland/custom-extension/qmltestapp
+target.path = $$[QT_INSTALL_EXAMPLES]/wayland/custom-extension/qml-client
INSTALLS += target
diff --git a/examples/wayland/custom-extension/qmltestapp/qml.qrc b/examples/wayland/custom-extension/qml-client/qml.qrc
index 5f6483ac3..5f6483ac3 100644
--- a/examples/wayland/custom-extension/qmltestapp/qml.qrc
+++ b/examples/wayland/custom-extension/qml-client/qml.qrc
diff --git a/examples/wayland/custom-extension/testapp/testapp.pro b/examples/wayland/custom-extension/testapp/testapp.pro
deleted file mode 100644
index 062210e9a..000000000
--- a/examples/wayland/custom-extension/testapp/testapp.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-SOURCES += main.cpp
-
-CONFIG += c++11
-
-target.path = $$[QT_INSTALL_EXAMPLES]/wayland/custom-extension/testapp
-INSTALLS += target