Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Slots and Signals in QT – how to connect from another class
Forum Updated to NodeBB v4.3 + New Features

Slots and Signals in QT – how to connect from another class

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 5.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fiddler
    wrote on last edited by
    #1

    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:

    1. generate a signal from another class in another file ?
    2. generate a slot from another class in another file ?
    3. 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

    Thanks

    K 1 Reply Last reply
    0
    • F fiddler

      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:

      1. generate a signal from another class in another file ?
      2. generate a slot from another class in another file ?
      3. 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

      Thanks

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @fiddler

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        This tutorial is a pretty nice summary of how to develop an interface using PyQt and designer.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • F Offline
          F Offline
          fiddler
          wrote on last edited by
          #4

          Thanks
          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....

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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 :)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved