How do you do heavy processing calls without hanging the GUI?

144 views
Skip to first unread message

Jeff Bair

unread,
May 14, 2015, 9:29:26 PM5/14/15
to go-...@googlegroups.com
Hello,

I wrote a small example app that sleeps for 5 seconds when you press a button to show the kind of issue I'm talking about.

qml file:
go file:

I've tried looking around to find out how to do a go call on a separate thread than the GUI thread and have a callback but only found Workerscript.  However that uses a javascript file to do the thread processing and I'm not sure how to have the javascript file invoke a goroutine unless I expose that routine through some command line interface.  Ideally I'd like to work within the QML and go file.  Does anyone have a suggestion/direction on what I can do?

Thanks!

David Marceau

unread,
May 15, 2015, 6:50:43 AM5/15/15
to go-...@googlegroups.com
On 05/14/2015 09:29 PM, Jeff Bair wrote:
> Hello,
>
> I wrote a small example app that sleeps for 5 seconds when you press a
> button to show the kind of issue I'm talking about.
>
> qml file:
> https://gist.github.com/jeffbair/7162967ee6b61649e702
> go file:
> https://gist.github.com/jeffbair/968e8118262f07b23329
>
> I've tried looking around to find out how to do a go call on a separate
> thread than the GUI thread and have a callback but only found Workerscript
> <http://doc.qt.digia.com/qt-5.2/qml-qtquick-workerscript.html>. However
> that uses a javascript file to do the thread processing and I'm not sure
> how to have the javascript file invoke a goroutine unless I expose that
> routine through some command line interface. Ideally I'd like to work
> within the QML and go file. Does anyone have a suggestion/direction on
> what I can do?
>
> Thanks!
>

You definitely need to expose some kind of routine from the go side.
It's a bit dated, but checkout search for "loadReportDataIntoGui" within
the .go source file:
https://github.com/omac777/goqmlsnowloadcount/blob/master/snowloadcountmain.go
-notice "qmlobject" and "ctrl" are used in it
-notice within load ReportDataIntoGui() has "go func() { ... }". That's
the trick. That's passing that part as separate task within this gopher
application. In fact when I load in all the data for all the different
gui controls, I'm attempting to do it in parallel and the gui doesn't
freeze up. The sample runs on ubuntu phone or ubuntu desktop just as
well. What makes it ubuntu specific is my choice of ubuntu-specific
qtcontrols rather than the Qt-shipped qtcontrols on the .qml-side.
https://github.com/omac777/goqmlsnowloadcount/tree/master/ui

go func() {
ctrl.SingleAxleMessage = strconv.Itoa( ctrl.Snldb.getSingleAxleTotal() )
qml.Changed(ctrl, &ctrl.SingleAxleMessage)
}()

There are probably better ways, but this one should still work.

Jeff Bair

unread,
May 18, 2015, 9:22:53 PM5/18/15
to go-...@googlegroups.com
Ah, I see, thanks!

Now I'm trying to make a sort of "Loading Dialog" while this process is running and close it right after the process finishes.  I can't seem to find how to get a callback to do this though from the go side or the qml side.  I've updated my gist files with an example of what I mean:
Is there a way I can use qml.Changed to ask the loadDialog to close or set visible to false somehow?

Jeff Bair

unread,
May 18, 2015, 10:11:18 PM5/18/15
to go-...@googlegroups.com
Actually I figured it out, the trick is to use the ObjectName call to manipulate child objects in the qml file.  I've updated my gists for my latest example in case people see this for reference:
Reply all
Reply to author
Forward
0 new messages