Skip to content
Snippets Groups Projects
Commit e8241ada authored by Kai Koehne's avatar Kai Koehne Committed by hjk
Browse files

Debugger: Add simple app to test mixed QML/CPP debugging (QQuick2)


Change-Id: Id744e3306da20bd7e2051ec4c45e3475084b64bc
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 1ef6c2b1
No related branches found
No related tags found
No related merge requests found
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
#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"
#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)
#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
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
}
#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)
#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
plugin myplugin
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
}
}
TEMPLATE = subdirs
SUBDIRS += app.pro myplugin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment