Commits

Hector Miuler Malpica Gallegos  committed bccf49d Draft

prueba hilos con qt

  • Participants

Comments (0)

Files changed (6)

+\.idea
+target
+# DEMO sobre comunicacion entre threads qt
+
+
+
+## Instalación
+
+Se necesita también las librerias nativas para qt, esta parta falta completar.
+
+name := "DemoQThreads"
+
+version := "1.0"
+
+libraryDependencies ++= Seq(
+    "junit" % "junit" % "4.10" % "test",
+    "org.specs2" %% "specs2" % "1.12.1" % "test"
+)
+

File lib/qtjambi-4.7.0.jar

Binary file added.

File project/plugins.sbt

+
+resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
+
+addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0-SNAPSHOT")
+

File src/main/scala/com/miuler/demo/qthreads/Main.scala

+package com.miuler.demo.qthreads
+
+import com.trolltech.qt.gui._
+import com.trolltech.qt.core.{QObject, QRunnable}
+import com.trolltech.qt.QThread
+import com.trolltech.qt.core.Qt.ConnectionType
+
+
+object Main {
+  def main(argv: Array[String]) {
+    QApplication.initialize(argv)
+    new WindowMain show()
+    QApplication.exec()
+  }
+}
+
+class WindowMain extends QWidget {
+
+  private val _label = new QLabel("Esta es la ventana principal que capturara los eventos")
+  private val _layout = new QGridLayout()
+  _layout.addWidget(_label)
+  _layout.addWidget(new QPushButton("Hola"))
+  setLayout(_layout)
+
+  private val _demoRunnable = new DemoRunnable
+  private val _demoThread = new QThread(_demoRunnable)
+  _demoRunnable.moveToThread(_demoThread)
+  _demoRunnable.messageSignal.connect(this, "updateLabel(String)", ConnectionType.QueuedConnection)
+  _demoThread.start()
+  println("Thread running")
+
+  def updateLabel(msg: String) {
+    _label.setText(msg)
+  }
+
+}
+
+class DemoRunnable extends QObject with Runnable {
+
+  val messageSignal = new Signal1[String]
+
+  def run() {
+    println("DemoRunnable")
+    Thread.sleep(5000)
+    messageSignal.emit("Hola esta es una prueba")
+  }
+}
+
+
+
+
+
+
+/*
+public class QtThreadTest extends QDialog {
+
+  private QLabel label = new QLabel("Hello world !!!");
+
+  private class MyThread extends QObject implements Runnable {
+
+    public QObject.Signal1<String> messageSignal = new
+        QObject.Signal1<String>();
+
+    public void run() {
+
+      try {
+        Thread.sleep(1000);
+      } catch (InterruptedException e) {
+        e.printStackTrace();
+      }
+      this.messageSignal.emit("Hello world from MyThread !!!");
+    }
+  }
+
+  private void updateLabel(String message) {
+
+    this.label.setText(message);
+  }
+
+  public QtThreatTest() {
+
+    QGridLayout layout = new QGridLayout();
+    layout.addWidget(label);
+    this.setLayout(layout);
+
+    MyThread mt = new MyThread();
+    mt.messageSignal.connect(this, "updateLabel(String)",
+      ConnectionType.QueuedConnection);
+
+    QThread t = new QThread(mt);
+    t.start();
+    System.out.println("Thead running...");
+  }
+
+  public static void main(final String[] args) {
+    QApplication.initialize(args);
+    new QtThreadTest().show();
+    QApplication.exec();
+  }
+}
+*/