forked from qt-creator/qt-creator
Debugger: Add simple app to test mixed QML/CPP debugging (QQuick2)
Change-Id: Id744e3306da20bd7e2051ec4c45e3475084b64bc Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
@@ -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
|
||||
@@ -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"
|
||||
@@ -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)
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
plugin myplugin
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += app.pro myplugin
|
||||
Reference in New Issue
Block a user