Timer available as a type now, remove exported object from runner
authorKevin Krammer <kevin.krammer@kdab.com>
Wed, 13 Mar 2013 13:47:00 +0000 (14:47 +0100)
committerKevin Krammer <kevin.krammer@kdab.com>
Wed, 13 Mar 2013 13:47:00 +0000 (14:47 +0100)
examples/test.qml
main.cpp

index 8627793..48be168 100644 (file)
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
-import QtQuick 1.0
+import QtCore 1.0
 import QtGui 1.0
 
 Widget {
   windowTitle: qsTr("Cool Test App")
   size: Qt.size(300, 500)
 
+
   property int counter: 0
 
   function myFunc()
@@ -32,12 +33,21 @@ Widget {
     counter++;
   }
 
-  Component.onCompleted: _timer.timeout.connect(myFunc)
+  Timer {
+    id: timer
+    interval: 1000
+    onTimeout: myFunc()
+  }
 
   VBoxLayout {
     Label {
       text: "Hallo ASCII-safe Kevin!!! " + counter
     }
+    PushButton {
+      text: "Run Timer"
+      checkable: true
+      onToggled: checked ? timer.start() : timer.stop()
+    }
     Label {
       id: secondLabel
       text: "Wie geht es"
index 1305e2d..533997c 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -25,7 +25,6 @@
 #include <QDeclarativeEngine>
 #include <QDir>
 #include <QFileInfo>
-#include <QTimer>
 #include <QWidget>
 
 int main(int argc, char **argv)
@@ -38,18 +37,12 @@ int main(int argc, char **argv)
       return -1;
   }
 
-  QTimer timer;
-  timer.setInterval(1000);
-  timer.start();
-
   const QFileInfo qmlFile(QDir::current(), arguments[1]);
   const QUrl documentUrl = QUrl::fromLocalFile(qmlFile.absoluteFilePath());
 
   DeclarativeWidgetsDocument document(documentUrl);
   QObject::connect(document.engine(), SIGNAL(quit()), &app, SLOT(quit()));
 
-  document.setContextProperty("_timer", &timer);
-
   QWidget *widget = document.create<QWidget>();
   if (widget)
     widget->show();