From e8241adae3aa160aa2e119f16f9a4b8afcdc480e Mon Sep 17 00:00:00 2001 From: Kai Koehne <kai.koehne@nokia.com> Date: Fri, 20 Jan 2012 16:20:55 +0100 Subject: [PATCH] Debugger: Add simple app to test mixed QML/CPP debugging (QQuick2) Change-Id: Id744e3306da20bd7e2051ec4c45e3475084b64bc Reviewed-by: hjk <qthjk@ovi.com> --- tests/manual/debugger/qquick2/app.pro | 13 ++++++ tests/manual/debugger/qquick2/main.cpp | 41 +++++++++++++++++++ .../debugger/qquick2/myplugin/myplugin.cpp | 11 +++++ .../debugger/qquick2/myplugin/myplugin.h | 15 +++++++ .../debugger/qquick2/myplugin/myplugin.pro | 26 ++++++++++++ .../debugger/qquick2/myplugin/mytype.cpp | 37 +++++++++++++++++ .../manual/debugger/qquick2/myplugin/mytype.h | 35 ++++++++++++++++ tests/manual/debugger/qquick2/myplugin/qmldir | 1 + tests/manual/debugger/qquick2/qml/main.qml | 29 +++++++++++++ tests/manual/debugger/qquick2/qquick2.pro | 3 ++ 10 files changed, 211 insertions(+) create mode 100644 tests/manual/debugger/qquick2/app.pro create mode 100644 tests/manual/debugger/qquick2/main.cpp create mode 100644 tests/manual/debugger/qquick2/myplugin/myplugin.cpp create mode 100644 tests/manual/debugger/qquick2/myplugin/myplugin.h create mode 100644 tests/manual/debugger/qquick2/myplugin/myplugin.pro create mode 100644 tests/manual/debugger/qquick2/myplugin/mytype.cpp create mode 100644 tests/manual/debugger/qquick2/myplugin/mytype.h create mode 100644 tests/manual/debugger/qquick2/myplugin/qmldir create mode 100644 tests/manual/debugger/qquick2/qml/main.qml create mode 100644 tests/manual/debugger/qquick2/qquick2.pro diff --git a/tests/manual/debugger/qquick2/app.pro b/tests/manual/debugger/qquick2/app.pro new file mode 100644 index 00000000000..2994749979c --- /dev/null +++ b/tests/manual/debugger/qquick2/app.pro @@ -0,0 +1,13 @@ +QT += declarative quick + +macx:CONFIG -= app_bundle + +DEFINES += SRCDIR=\\\"$$PWD\\\" + +SOURCES += main.cpp + +OTHER_FILES += qml/main.qml + +qml.files = qml +qml.path = . +DEPLOYMENT += qml diff --git a/tests/manual/debugger/qquick2/main.cpp b/tests/manual/debugger/qquick2/main.cpp new file mode 100644 index 00000000000..b66c3d9af9b --- /dev/null +++ b/tests/manual/debugger/qquick2/main.cpp @@ -0,0 +1,41 @@ +#include <QGuiApplication> +#include <QQuickView> +#include <QDeclarativeContext> +#include <QDeclarativeEngine> +#include <QDebug> + +class Backend : public QObject { + Q_OBJECT + +public: + Q_INVOKABLE void greet(const QString &toWhom); +signals: + void greetBack(const QString &toWhom); +}; + + +void Backend::greet(const QString &toWhom) +{ + // bp here should be hit on startup + qDebug() << "hello" << toWhom; + + // let's call back through signal ... + emit greetBack("QML"); +} + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + + QQuickView view; + Backend backend; + view.rootContext()->setContextProperty("backend", &backend); + + view.setSource(QUrl::fromLocalFile(SRCDIR"/qml/main.qml")); + view.show(); + + app.exec(); +} + +#include "main.moc" diff --git a/tests/manual/debugger/qquick2/myplugin/myplugin.cpp b/tests/manual/debugger/qquick2/myplugin/myplugin.cpp new file mode 100644 index 00000000000..879e5beace7 --- /dev/null +++ b/tests/manual/debugger/qquick2/myplugin/myplugin.cpp @@ -0,0 +1,11 @@ +#include "myplugin.h" +#include "mytype.h" + +void MyPlugin::registerTypes(const char *uri) +{ + // @uri mymodule + // bp here should be hit on startup + qmlRegisterType<MyType>(uri, 1, 0, "MyType"); +} + +Q_EXPORT_PLUGIN(MyPlugin) diff --git a/tests/manual/debugger/qquick2/myplugin/myplugin.h b/tests/manual/debugger/qquick2/myplugin/myplugin.h new file mode 100644 index 00000000000..334e635fc34 --- /dev/null +++ b/tests/manual/debugger/qquick2/myplugin/myplugin.h @@ -0,0 +1,15 @@ +#ifndef MYPLUGIN_H +#define MYPLUGIN_H + +#include <QtDeclarative/qdeclarative.h> +#include <QtDeclarative/QDeclarativeExtensionPlugin> + +class MyPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT + +public: + void registerTypes(const char *uri); +}; + +#endif // MYPLUGIN_H diff --git a/tests/manual/debugger/qquick2/myplugin/myplugin.pro b/tests/manual/debugger/qquick2/myplugin/myplugin.pro new file mode 100644 index 00000000000..09116f6977b --- /dev/null +++ b/tests/manual/debugger/qquick2/myplugin/myplugin.pro @@ -0,0 +1,26 @@ +TEMPLATE = lib +TARGET = myplugin +QT += declarative +CONFIG += qt plugin + +TARGET = $$qtLibraryTarget($$TARGET) +uri = qquick1 + +# Input +SOURCES += \ + myplugin.cpp \ + mytype.cpp + +HEADERS += \ + myplugin.h \ + mytype.h + +OTHER_FILES = qmldir + +!equals(_PRO_FILE_PWD_, $$OUT_PWD) { + copy_qmldir.target = $$OUT_PWD/qmldir + copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir + copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" + QMAKE_EXTRA_TARGETS += copy_qmldir + PRE_TARGETDEPS += $$copy_qmldir.target +} diff --git a/tests/manual/debugger/qquick2/myplugin/mytype.cpp b/tests/manual/debugger/qquick2/myplugin/mytype.cpp new file mode 100644 index 00000000000..a3719a9c44e --- /dev/null +++ b/tests/manual/debugger/qquick2/myplugin/mytype.cpp @@ -0,0 +1,37 @@ +#include <QtCore/QTimer> +#include <QtCore/QTime> +#include <QtDeclarative/qdeclarative.h> + +#include "mytype.h" + +MyType::MyType(QObject *parent) + : QObject(parent) +{ + updateTimerText(); + m_timer = new QTimer(this); + m_timer->setInterval(1000); + connect(m_timer, SIGNAL(timeout()), SLOT(updateTimerText())); + m_timer->start(); +} + +QString MyType::timeText() const +{ + // bp here should be hit on every second + return m_timeText; +} + +void MyType::setTimeText(const QString &text) +{ + if (m_timeText != text) { + m_timeText = text; + emit timeChanged(m_timeText); + } +} + +void MyType::updateTimerText() +{ + const QTime t = QTime::currentTime(); + setTimeText(t.toString(QLatin1String("HH:mm:ss"))); +} + +QML_DECLARE_TYPE(MyType) diff --git a/tests/manual/debugger/qquick2/myplugin/mytype.h b/tests/manual/debugger/qquick2/myplugin/mytype.h new file mode 100644 index 00000000000..68fc5d5d40b --- /dev/null +++ b/tests/manual/debugger/qquick2/myplugin/mytype.h @@ -0,0 +1,35 @@ +#ifndef MYTYPE_H +#define MYTYPE_H + +#include <QtCore/QObject> +#include <QtCore/QString> + +class QTimer; + +class MyType : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString timeText READ timeText WRITE setTimeText NOTIFY timeChanged) + +public: + MyType(QObject *parent = 0); + + QString timeText() const; + void setTimeText(const QString &text); + +signals: + void timeChanged(const QString &newText); + +private slots: + void updateTimerText(); + +private: + QString m_timeText; + QTimer *m_timer; + + Q_DISABLE_COPY(MyType) +}; + +#endif // MYTYPE_H + diff --git a/tests/manual/debugger/qquick2/myplugin/qmldir b/tests/manual/debugger/qquick2/myplugin/qmldir new file mode 100644 index 00000000000..a244fa6ad8e --- /dev/null +++ b/tests/manual/debugger/qquick2/myplugin/qmldir @@ -0,0 +1 @@ +plugin myplugin diff --git a/tests/manual/debugger/qquick2/qml/main.qml b/tests/manual/debugger/qquick2/qml/main.qml new file mode 100644 index 00000000000..f9d3621b355 --- /dev/null +++ b/tests/manual/debugger/qquick2/qml/main.qml @@ -0,0 +1,29 @@ +import QtQuick 2.0 +import myplugin 1.0 + +Rectangle { + width: 100 + height: 100 + + MyType { + id: time + } + + Component.onCompleted: { + // bp here should be hit on startup + backend.greet("C++"); + } + + Connections { + target: backend + onGreetBack: { + console.log("hello \"" + toWhom + "\""); + } + } + + Text { + anchors.centerIn: parent + // bp here should be hit every second + text: time.timeText + } +} diff --git a/tests/manual/debugger/qquick2/qquick2.pro b/tests/manual/debugger/qquick2/qquick2.pro new file mode 100644 index 00000000000..c376f199992 --- /dev/null +++ b/tests/manual/debugger/qquick2/qquick2.pro @@ -0,0 +1,3 @@ +TEMPLATE = subdirs + +SUBDIRS += app.pro myplugin -- GitLab