call listmodel append within go source

238 views
Skip to first unread message

Gerald Stan

unread,
Oct 3, 2014, 1:45:13 PM10/3/14
to go-...@googlegroups.com
Hello,

I use a listmodel and want to call the method append in the defined method named as Loaded:

qml file:
ListModel {
        id: largeModel

        Component.onCompleted: {
            ctrl.loaded(largeModel)
        }
    }
}

go app:
func (ctrl *Control) Loaded(obj qml.Object) {
  fmt.Println("onCompleted() called")

  fmt.Println(obj.Int("count"))

  obj.Call("append", "\"name\":\"Person \"+0 , \"age\": 20, \"gender\": \"Male\"")
}

here the output:

go run tableview.go 

onCompleted() called

0

fatal error: unexpected signal during runtime execution

[signal 0xb code=0x1 addr=0x400000001 pc=0x555f4a1]

whats the right way to call it?

Thanks,

-Gerald

Gerald Stan

unread,
Oct 4, 2014, 5:56:53 PM10/4/14
to go-...@googlegroups.com
any comment on this?

Andrew Jackman

unread,
Oct 4, 2014, 6:16:20 PM10/4/14
to Gerald Stan, Go QML
I think this may be what you're looking for:


-----
A. R. Jackman
USA: 801-432-0541
jac...@jackmanlabs.com

CONFIDENTIALITY NOTICE: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure, or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.

--
You received this message because you are subscribed to the Google Groups "go-qml" group.
To unsubscribe from this group and stop receiving emails from it, send an email to go-qml+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gerald Stan

unread,
Oct 4, 2014, 6:36:43 PM10/4/14
to go-...@googlegroups.com, gerald...@gmail.com
ok, seems a similar issue.... whats the right way to call append in this case?

Gerald Stan

unread,
Oct 4, 2014, 6:57:42 PM10/4/14
to go-...@googlegroups.com, gerald...@gmail.com
the interesting thing is i can call the method clear (http://qt-project.org/doc/qt-5/qml-qtqml-models-listmodel.html#clear-method) without any issues:
obj.Call("clear")

Gerald Stan

unread,
Oct 5, 2014, 8:56:26 AM10/5/14
to go-...@googlegroups.com, gerald...@gmail.com
i solved this in the following way:
i simply do a json encoding on the go side as well as json decoding on the javascript side...

i extended the qml file with a js function:
function myAppend(json) {
          largeModel.append(JSON.parse(json))
}

i extended the go source with:
type tableEntry struct {
    Name string `json:"name"`
    Age string `json:"age"`
    Gender string `json:"gender"`
}

func (ctrl *Control) Loaded(obj qml.Object) {
  fmt.Println("onCompleted() called")

  fmt.Println(obj.Int("count")) // count should be 0 at the beginning, since the table is empty

  for i := 0; i < 100; i++ {
    m := tableEntry{"Person " + intToString(i), "10", "Male"}
    jsonData, err := json.Marshal(m)
    if err != nil {
      fmt.Println("json error")
    }

    obj.Call("myAppend", string(jsonData))
  }

  fmt.Println(obj.Int("count")) // count should be 100 after we insert 100 elements
}

please give me some feedback...
are there plans to fix this within golang qml?

Gustavo Niemeyer

unread,
Oct 6, 2014, 2:58:02 AM10/6/14
to Gerald Stan, Go QML
Hi Gerald,

This is the same issue described here:

https://github.com/go-qml/qml/issues/90

It will be addressed.
--

gustavo @ http://niemeyer.net
--

gustavo @ http://niemeyer.net

Jakob Maier

unread,
Jul 3, 2016, 7:03:33 AM7/3/16
to go-qml, gerald...@gmail.com
Is there already a solution for this Issue?
Reply all
Reply to author
Forward
0 new messages