- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我还没有找到使用 Clojure 的解决方案REPL在网络上使用 Qt。基本上,问题是 REPL 在您调用 QApplication/exec 以显示 UI 时立即挂起。你不能 C-c C-c 回到 REPL,关闭事件的 Qt 窗口似乎会杀死整个 Clojure 进程。
现在不可能在代理中简单地调用 QApplication/processEvents,除非代理运行在与您创建 Qt 小部件完全相同的线程中。我花了两天时间才弄明白这个问题,我看到其他人也有同样的问题/问题,但没有解决方案。所以这是我的代码:
(add-classpath "file:///usr/share/java/qtjambi.jar")
(ns qt4-demo
(:import (com.trolltech.qt.gui QApplication QPushButton QFont QFont$Weight)
(com.trolltech.qt.core QCoreApplication)
(java.util Timer TimerTask)
(java.util.concurrent ScheduledThreadPoolExecutor TimeUnit))
(:require swank.core))
(defn init []
(QApplication/initialize (make-array String 0)))
(def *gui-thread* (new java.util.concurrent.ScheduledThreadPoolExecutor 1))
(def *gui-update-task* nil)
(def *app* (ref nil))
(defn update-gui []
(println "Updating GUI")
(QApplication/processEvents))
(defn exec []
(.remove *gui-thread* update-gui)
(def *gui-update-task* (.scheduleAtFixedRate *gui-thread* update-gui 0 150 (. TimeUnit MILLISECONDS))))
(defn stop []
(.remove *gui-thread* update-gui)
(.cancel *gui-update-task*))
(defmacro qt4 [& rest]
`(do
(try (init) (catch RuntimeException e# (println e#)))
~@rest
))
(defmacro with-gui-thread [& body]
`(.get (.schedule *gui-thread* (fn [] (do ~@body)) (long 0) (. TimeUnit MILLISECONDS))))
(defn hello-world []
(with-gui-thread
(qt4
(let [app (QCoreApplication/instance)
button (new QPushButton "Go Clojure Go")]
(dosync (ref-set *app* app))
(doto button
(.resize 250 100)
(.setFont (new QFont "Deja Vu Sans" 18 (.. QFont$Weight Bold value)))
(.setWindowTitle "Go Clojure Go")
(.show)))))
(exec))
基本上它使用 ScheduledThreadPoolExecutor 类来执行所有 Qt 代码。您可以使用 with-gui-thread 宏来更轻松地从线程内调用函数。这使得无需重新编译即可即时更改 Qt UI 成为可能。
最佳答案
如果您想使用 REPL 中的 Qt 小部件,QApplication/invokeLater
或 QApplication/invokeAndWait
可能是您想要的。您可以将它们与代理一起使用。鉴于此:
(ns qt4-demo
(:import (com.trolltech.qt.gui QApplication QPushButton)
(com.trolltech.qt.core QCoreApplication)))
(def *app* (ref nil))
(def *button* (ref nil))
(def *runner* (agent nil))
(defn init [] (QApplication/initialize (make-array String 0)))
(defn exec [] (QApplication/exec))
(defn hello-world [a]
(init)
(let [app (QCoreApplication/instance)
button (doto (QPushButton. "Go Clojure Go") (.show))]
(dosync (ref-set *app* app)
(ref-set *button* button)))
(exec))
然后来自 REPL:
qt4-demo=> (send-off *runner* hello-world)
#<Agent@38fff7: nil>
;; This fails because we are not in the Qt main thread
qt4-demo=> (.setText @*button* "foo")
QObject used from outside its own thread, object=QPushButton(0x8d0f55f0) , objectThread=Thread[pool-2-thread-1,5,main], currentThread=Thread[main,5,main] (NO_SOURCE_FILE:0)
;; This should work though
qt4-demo=> (QApplication/invokeLater #(.setText @*button* "foo"))
nil
qt4-demo=> (QApplication/invokeAndWait #(.setText @*button* "bar"))
nil
关于qt - 如何将 Clojure REPL 与 Qt Jambi 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1691453/
我想在 Sublime Text 中创建一个快捷方式来执行以下操作: 如果 R 的 REPL 已打开,请将所选文本发送到此 REPL 否则在新窗口中打开 R REPL 并将文本发送到此 REPL。 我
和这里的一些提问者一样,我是 Lisp 的新手。我正在浏览 Practical Common Lisp书,但回过头来看看设置网络应用程序有多么容易,所以我一直在关注 this教程,以及 updated
我无法理解我不理解的复合“入门”示例。当我从 http://weavejester.github.com/compojure/docs/getting-started.html 运行示例时 ...我在
这个问题在这里已经有了答案: Running a Common Lisp function from a Terminal command prompt (4 个答案) 关闭 8 年前。 我正在尝试
我正在尝试使用 REPL 中给出的文本更改 Node 的 REPL 的提示。 我最初的尝试是这样的。 import repl from 'repl' let PROMPT = 'original >
我使用 Scala 语言已经有几个月了,并且已经在 Scala 中创建了几个项目。我发现 Scala REPL(至少是它的 IntelliJ 工作表实现)对于快速开发来说非常方便。我可以编写代码,看看
我进入正题。我已经安装了 SublimeText 3,我还通过 Package Control 安装了 SublimeREPL,我基本上已经根据需要进行了设置。 让我烦恼的主要事情是,每次我构建一个
我尝试使用相同的算法运行两个阶乘函数,一个在 Scala 中,另一个在 Clojure 中: // Scala: def factorial(n:Int) = (1 to n).foldLeft(1:
我开始喜欢 Scala REPL 使用 resX 引用以前计算的能力,并且想知道是否有一种方法可以在 Python/bpython/iPython REPL 中访问它。 最佳答案 默认的 python
我进入正题。我已经通过 Package Control 安装了 SublimeREPL,并且我已经按照我的需要进行了很多设置。 唯一困扰我的是,每次我构建 python 脚本 (CTRL+B) 时,都
定义完变量、函数等之后,你能不能把你在REPL上所做的也保存成一个文本.clj文件? 最佳答案 大多数人通过诸如广告 Eclipse/Emacs/vim 之类的编辑器使用 repl,并且该编辑器能够保
Scala REPL 非常适合尝试不同的代码片段。如果可以使用 Scala REPL 中的 Maven 存储库中的库运行代码,那就太好了。如何将远程 Maven 存储库添加到 Scala REPL 类
常规 Clojure 复制 clojure.main/repl接受类似 :print 的选项, :prompt和 :eval这让您可以连接并覆盖 repl 的行为。 例如。 (clojure.main
我正在开发我的第一个全栈 Clojure 应用程序。我已经设法让以下内容在 Linux Mint 中正常工作: 莱宁根 figwheel + garden[auto] = 使用热代码和 CSS 重新加
运行基本的 df.show() post spark notebook 安装 在 spark-notebook 上运行 scala - spark code 时出现以下错误。知道这种情况何时发生以及如
我一直在尝试 Javascript haskell-js库,但我偶然发现了 Coffeescript REPL 的奇怪行为。 使用节点,以下示例可以按预期工作: $ node require('has
在 Swift REPL 中,有什么方法可以保留 REPL 状态? 例如,我想在 REPL 中做一些工作,然后保存它,以便稍后加载。 这个概念可能被命名为保存/加载、暂停/恢复、快照/克隆、序列化/反
我正在尝试使用 REPL 来测试我的 java 代码。我已经设置了类路径并启动了 REPL,我可以在 REPL 中访问我的应用程序类。 我启动了一个进行 Web 服务调用的方法,它抛出了 java.l
嗨,我从 haskell 开始,并尝试设置我的 emacs 以进行开发。 我有 haskell-mod和 ghc-mod最新 emacs 24.3.1 . GHC 是 7.6.3 我创建了一个 has
我需要使用一个文档不足的 Java 库,如果有一种方法可以查看 REPL 中方法的签名(用于快速实验),它将对我有所帮助。考虑以下: user=> (import 'x.y.z.C) user=> (
我是一名优秀的程序员,十分优秀!