首页
/
行业洞察
/
正文
INDUSTRY INSIGHT · 深度
QML调用JS
📅 2026/11/2 18:39:23
✍️ 爱科研究院
👁 阅读 3,247
JS.pragma library var scope { } function call(msg) { var exp msg.toString(); console.log(exp) var data { expression : msg } try { var fun new Function(return ( exp );); data.result JSON.stringify(fun.call(scope), null, 2) console.log(scope: JSON.stringify(scope, null, 2) result: result) } catch(e) { console.log(e.toString()) data.error e.toString(); } return data; }QMLimport QtQuick 2.5 import QtQuick.Controls 1.5 import QtQuick.Layouts 1.2 import QtQuick.Window 2.2 import jsconsole.js as Util ApplicationWindow { id: root title: qsTr(JSConsole) width: 640 height: 480 menuBar: MenuBar { Menu { title: qsTr(File) MenuItem { text: qsTr(Exit) onTriggered: Qt.quit(); } } } ColumnLayout { anchors.fill: parent anchors.margins: 9 RowLayout { Layout.fillWidth: true TextField { id: input Layout.fillWidth: true focus: true onAccepted: { root.jsCall(input.text) } } Button { text: qsTr(Send) onClicked: { root.jsCall(input.text) } } } Item { Layout.fillWidth: true Layout.fillHeight: true Rectangle { anchors.fill: parent color: #333 border.color: Qt.darker(color) opacity: 0.2 radius: 2 } ScrollView { id: scrollView anchors.fill: parent anchors.margins: 9 ListView { id: resultView model: ListModel { id: outputModel } delegate: ColumnLayout { width: ListView.view.width Label { Layout.fillWidth: true color: green text: model.expression } Label { Layout.fillWidth: true color: blue text: model.result } Rectangle { height: 1 Layout.fillWidth: true color: #333 opacity: 0.2 } } } } } } function jsCall(exp) { var data Util.call(exp); outputModel.insert(0, data) } }创作不易小小的支持一下吧
📌 标签:
工业官网
设计趋势
AI 建站
SEO
获取完整报告 →
RELATED ARTICLES
推荐阅读
2026/11/2 18:39:23
从 FBX 到骨骼动画:MonoGame 快速完成 3D 模型加载与角色动作
2026/11/2 18:39:23
TCP四元组不同,为什么bind同一个源端口仍会失败?
2026/11/2 18:39:23
esp32-c3-adblock 如何切换上游 DNS:一行构建参数换到 1.1.1.1,10 分钟生效
2026/11/2 19:55:01
tree命令详解:高效管理目录结构的必备工具
2026/11/2 19:55:01
STL缩略图不显示?资源管理器扩展与Shell缩略图处理器实战
2026/11/2 19:55:01
贝叶斯时序模型+LLM+状态空间:文本数值联合预测落地
2026/11/2 19:55:01
Redis缓存一致性:原理、策略与高并发实践
2026/11/2 19:55:01
TDengine IDMP工业数据管理平台架构与应用实践
2026/11/2 19:50:00
产品经理与研发工程师:职业定位与能力模型对比
2026/11/2 1:03:35
工业SPI隔离方案:K64主控+MAX14431从设计到排查
2026/11/2 1:03:35
SPI隔离器MAX14431与PIC18F8722实现工业级稳定通信的实战指南
2026/11/2 1:03:35
雷达信号调制技术解析:从LFM到相位连续调频波形设计
2026/11/2 2:42:45
面向复杂光照与角度的宠物面部识别鲁棒性增强策略
2026/11/2 2:42:47
DRV8818PWPR与R7FA8M1AHECBD工业步进驱动实战指南
2026/11/2 2:42:50
STM32与DRV8818双极步进电机驱动方案:从选型到调试全流程解析
2026/11/2 2:42:45
面向复杂光照与角度的宠物面部识别鲁棒性增强策略
2026/11/2 2:42:47
DRV8818PWPR与R7FA8M1AHECBD工业步进驱动实战指南
2026/11/2 2:42:50
STM32与DRV8818双极步进电机驱动方案:从选型到调试全流程解析