Commit f7c9b4ee authored by Kai Koehne's avatar Kai Koehne Committed by hjk

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

Change-Id: I7b7983a795c3c72e611bd6531c84cf498fb15c9f
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 8287cbe1
QT += declarative
macx:CONFIG -= app_bundle
DEFINES += SRCDIR=\\\"$$PWD\\\"
SOURCES += main.cpp
OTHER_FILES += qml/main.qml
qml.files = qml
qml.path = .
DEPLOYMENT += qml
#include <QApplication>
#include <QDeclarativeView>
#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)
{
QApplication app(argc, argv);
QDeclarativeView 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
import QtQuick 1.1
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment