Slots and Signals in QT – how to connect from another class
So I use QT Designer for the User Interface (UI), and convert this to python using “pyuic5” which generates a ui.py file
As this file gets overwritten every-time I make any changes to the UI, I would like to to have another .py file which has a signal/slot class and I can program there without any worries about copy/paste issues to/from the auto-generated ui.py file.
But how do I:
- generate a signal from another class in another file ?
- generate a slot from another class in another file ?
- write back into the ui.py class, ie writing some text in a text field.
It is no problem doing the above if I keep all the code in the ui.py file, but it does become a copy/paste issue and prone to me making simple errors.
Any suggestions or is this really not doable.
I have searched the net a lot but nothing has come up and everything I have tried doesn't work
Using QT Designer 5.7, pyuic5.8 and python 3.6x
To start with I do not know any details of python. Therefore, it would be better to have someone from the python community to answer your question.
Anyway in C++ the signal are basically calls to member routine of another class. If you understand how to do that in python when the definitions of both objects are defined in different files, you can probably use QObject::connect
The coonects allow nowadays two different methods to connect between objects. One group is the older style string-based and the newer style is functor-based. Both methods do basically the same thing, but IMHO the fuctor-based method is more obvious, when you understand the concept of functors.
- You basically have a pointer to an object who is emitting a signal.
- The signal is defined as functor &class1::sig1.
- As next you have the pointer to the receiving object.
- Folllowed by the functor to receiving function &class2::slt1
There is one obstacle with the calling list. It is much easier to have identical parameter list on both sides. At list at the start, it should be less confusing for you.
The only thing I can offer is, that you throw questions and I may be able to answer from C++ perspective.
This tutorial is a pretty nice summary of how to develop an interface using PyQt and designer.
This is for a office automation application and it joins about 6 different applications together and one of the applications only uses python as the script lingo, so to prevent from having to translate python to C++, I thought it would be easier to just do the whole thing in python.
I was going to write a script to join the files, but the tutorial does it better I think.
So thanks a bunch and no doubt I will be back with more questions....
You're welcome !
If that answers you original question, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)