Home
Categories
WIKI
Topic
User
LANGUAGE:
中文
English
Golang+QML写的一个笔记工具
社区开发
2609
views ·
0
replies ·
To
floor
Go
Bluek404
deepin
2014-11-30 08:10
Author
20141130000349.png看见go-qml又更新了不少东西
然后顺便测试一下Deepin的QML控件
花了20分钟写了个小程序
翻了一遍Deepin的控件貌似没有需要用的= =
就只用了DWindow
直接上源码
package main
import (
"fmt"
"os"
"gopkg.in/qml.v1"
)
func main() {
if err := qml.Run(run); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}
func run() error {
engine := qml.NewEngine()
engine.Context().SetVar("goObject", &GoObject{})
component, err := engine.LoadFile("test.qml")
if err != nil {
return err
}
window := component.CreateWindow(nil)
window.Show()
window.Wait()
return nil
}
type GoObject struct {
text []string
Len int
}
func (g *GoObject) AddText(text string) {
g.text=append(g.text, text)
g.Len=len(g.text)
qml.Changed(g, &g.Len)
}
func (g *GoObject) GetText(index int) string {
return g.text[index]
}
func (g *GoObject) DelText(index int) {
g.text=append(g.text[:index],g.text[index+1:]...)
g.Len=len(g.text)
qml.Changed(g, &g.Len)
}
Copy the Code
import QtQuick 2.1
import Deepin.Widgets 1.0
DWindow {
id: window
color: Qt.rgba(1.0, 0.5, 0, 0.2)
width: 300
height: 300
TextInput {
id: input
x: 6
y: 7
width: 288
height: 20
font.pixelSize: 12
onAccepted: goObject.addText(text), text=""
}
ListView {
x: 6
y: 33
width: 288
height: 261
model: goObject.len
delegate:
MouseArea {
width: window.width
height: 15
onClicked: goObject.delText(index)
Text {
text: goObject.getText(index)
}
}
}
}
Copy the Code
顺便吐槽一下Deepin的控件好不稳定啊
运行的时候得启动好几遍
因为有机率runtime直接挂掉
以及QML太不灵活了,以后还是乖乖写html吧
下载(请先确认你安装了Deepin的QML控件,Deepin2014默认有):
64位:dtest.zip
-------------------------------
32位你得自己编译,因为go-qml直接使用了CPP文件所以无法交叉编译
--------------------------------
上面的下载我把engine.LoadFile方法换成了LoadString,所以可以编译成单文件
Reply
Like 0
Favorite
View the author
All Replies
No replies yet
Please
sign
in first
Featured Collection
Change
[Tutorial] deepin25 WSL Offline Installation Guide
UOS AI 2.8 Released! Three New Intelligent Agents & Major Evolution
Solid Q&A | deepin 25 Common Questions – The Immutable System Edition
New Thread
Popular Ranking
Change
Error configurar cara autenticacion biometrica
Hız
add screenshot to message sent early
HP Pavilion extremly slow
HP Printer smart tank 5105 not support
Popular Events
More
然后顺便测试一下Deepin的QML控件
花了20分钟写了个小程序
翻了一遍Deepin的控件貌似没有需要用的= =
就只用了DWindow
直接上源码
运行的时候得启动好几遍
因为有机率runtime直接挂掉
以及QML太不灵活了,以后还是乖乖写html吧
下载(请先确认你安装了Deepin的QML控件,Deepin2014默认有):
64位:dtest.zip
-------------------------------
32位你得自己编译,因为go-qml直接使用了CPP文件所以无法交叉编译
--------------------------------
上面的下载我把engine.LoadFile方法换成了LoadString,所以可以编译成单文件