Connecting to slots in handler file

More
25 Aug 2023 19:47 #278947 by Jox
I am starting a custom Qtvcp screen from scratch and I need help with connecting to a slot created in the .ui file. I followed the directions in the in the linuxcnc tutorial:
linuxcnc.org/docs/devel/html/gui/qtvcp.html
I created a push button and connected the clicked signal to the main page slot, test_button(). In the handler file I created a function, def test_button(self): in the HandlerClass():

Obviously I need help fixing the problem, but can some help explain how these files are even connected.  I have a class (HandlerClass) in the handler.py file and I don't even know what program is creating an object from this class. I can only guess it is from the .hal file but I don't know where.  And since the QT screens are built from the QMainWidget class, I don't know how a function in the HandlerClass would ever find a slot called test_button() coming from a .ui file.  I hope that makes sense.  

 
Attachments:

Please Log in or Create an account to join the conversation.

More
26 Aug 2023 01:46 #278975 by cmorley
You have tabs mixed with spaces. Python is very picky about this.
It made the test_button function be outside the handler file context so it wasn't seen.

I removed the tabs and change them to spaces - works now.
When doing python work I configure my editor to make the tab key add 4 spaces rather then one tab.

Qtvcp imports the handler file into the window object then loads the ui file which tries to connect the signals.

Chris
Attachments:

Please Log in or Create an account to join the conversation.

More
27 Aug 2023 02:58 #279068 by persei8
I gave up on connecting signals in the ui file. Whenever you move a widget around, the connection is lost and you have to redefine it. So now I just use a seperate connections class that defines all the signal/slot connections. The handler imports the connections class and creates an object when it's ready for the connections to be made. You could also just include it in the handler, but having a separate module makes it ..... modular.
Jim
 

Please Log in or Create an account to join the conversation.

More
19 Sep 2023 02:47 #281131 by Jox
Sorry for the late response.
Thanks for the help. You are absolutely right about Python being picky and I have been learning all the rules. It ended up being a signal that was hidden or not connected to anything but it was still being created. Either way I finally found it.
Thanks for the help!

Please Log in or Create an account to join the conversation.

More
19 Sep 2023 02:49 #281132 by Jox
I like that. It definitely makes sense, especially because the handler file is getting pretty lengthy. Thanks, I give it a try.

Please Log in or Create an account to join the conversation.

Moderators: cmorley
Time to create page: 0.158 seconds
Powered by Kunena Forum