How to create and use a background task?
Posted
#1
(In Topic #1547)
Regular

I was hoping the wiki to have an example here /comp/gb/task - Gambas Documentation but unfortunately it does not have one.
Posted
Regular

Code (gambas)
And my FMain so far:
Code (gambas)
- ' Gambas class file
- MyTaskInstance.Start()
However the events are not being fired on FMain.
Posted
Guru

You must make the task print text output. then in FMain use the tasks Read event.
TestiClass.class
FMain.class
Code (gambas)
- ' Gambas class file
- ' MyTaskInstance.Start() ' nah, the Main sub is automatically run when a task is created.
- ' so create it to start it...
- ' Note, be careful using Object.Attach as it can steal a classes internal event catching. prefer using Observer.class or just use "As" like i have above.
- ' use Task.class Read event.
- Print TestiClass.TmpStr
Task.class is built only to transmit text data in the read event.
It runs as a completely separate process so you cannot treat it like a normal class in any way. it does not link like a usual application class/module does.
"The Main method is run by a fork. It can access every other part of the program, except that the parent process will not see any change done by the task. "
Posted
Regular

Now my FMain.class is this:
Code (gambas)
- ' Gambas class file
Code (gambas)
PS: I'm also willing to learn from and inspect code made by some one else about Task.class in case you could link me to such.
Posted
Guru

Try Sleep instead.
Ps. i had not noticed you made the events Private not Public , events never trigger if Private.
Public Sub TaskWithevents_Read(Txt As String)
Posted
Regular

Here's the final code that works for some one else to find and benefit from:
FMain.class:
Code (gambas)
TestiClass.class:
Code (gambas)
- Inherits Task
- 'Input can only be set here, after that they are read only
- _Arguments = Arguments
- 'Parent can observe Prints by subscribing with Read event
- Print "Initialized"
- 'Now lets do something slow here and sen progress messages
- Wait Interval 'Wait seems to work and I didn't need to switch to Sleep
- Wait Interval
- 'And inform how we are finally done
- Print "Done"
There was another problem also. I keep two GNU/Linux operating systems installed and the code above doesn't work on the other one. When code execution on FMain reaches line my program will auto close and return to Gambas with the following error message:
Code
symbol lookup error: /usr/lib64/gambas3/gb.qt6.so: undefined symbol: _ZN18QThreadPoolPrivate13qtGuiInstanceEv, version Qt_6_PRIVATE_APII tried a few methods do disable Qt 6 but they did not work: If I right click the Gambas dot-desktop icon and select "Run with QT 5" I still get the Qt_6 error. Same if I recompile Gambas with
Code
$ ./configure -C --disable-qt6
Posted
Administrator

What system are you running where it works and what system where it doesn't?JumpyVB said
There was another problem also. I keep two GNU/Linux operating systems installed and the code above doesn't work on the other one. When code execution on FMain reaches line my program will auto close and return to Gambas with the following error message:Any idea how to investigate and troubleshoot this?Code
symbol lookup error: /usr/lib64/gambas3/gb.qt6.so: undefined symbol: _ZN18QThreadPoolPrivate13qtGuiInstanceEv, version Qt_6_PRIVATE_API
I tried a few methods do disable Qt 6 but they did not work: If I right click the Gambas dot-desktop icon and select "Run with QT 5" I still get the Qt_6 error. Same if I recompile Gambas with. Qt 6 will still somehow get to the end product.Code
$ ./configure -C --disable-qt6
Does the distro only provide qt6 and no more qt5?
Could you post the system info of both systems (in IDE menu ? -> System Info)
You might have a too new qt6 version as it seems not to support some symbol call
If I remember correctly there have been post on mailing list several times in recent past of systems breaking Gambas (mainly rolling releases like Arch), because of newer qt6 libraries. I guess this might be something like that.
So, detailed info is needed to compare library version (hence the system info). If this is the case it should be reported on bugtracker, so Benoit can have a look at it.
If in IDE go to Project -> Properties -> Tab Component to set your project to qt5.JumpyVB said
Is there a way to enforce Gambas not to use Qt 6 in any way but only Qt 5 only?
I even made a template so my application can be newly created with qt5 instead of having to choose the general qt application that gives me gb.gui.qt instead of gb.qt5.
Hope this helps…
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
Posted
Regular

- The code works in Open Suse Tumbleweed.
- I have been using the default gb.gui component.
- I just tried replacing gb.gui with gb.qt5 and the code now runs as it should.
- I confirm my issue is solved now. Thank you so much for helping me.
Posted
Administrator

Good you have it working now. Glad I could help.JumpyVB said
- I just tried replacing gb.gui with gb.qt5 and the code now runs as it should.
- I confirm my issue is solved now. Thank you so much for helping me.
Enjoy…
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
1 guest and 0 members have just viewed this.


