Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1113219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:49:28+00:00 2026-05-17T02:49:28+00:00

Thanks in advance for taking the time to read this. Apologies that it is

  • 0

Thanks in advance for taking the time to read this. Apologies that it is somewhat verbose. But hopefully it fully explains the problem. Stripped code demonstrating the issue is included.

I’m having an issue with PyQt4 SIGNAL/SLOTS. While I can make everything work fine if I am writing in a single file, I can’t make things work if I some of the functions I wish to use are moved to sub-directories/classes.

I’ve looked through the Python Bindings document I can see how this works when using a single file. But what I am trying to do is this:

  • main.py file in root dir which contains the MainWindow __init__ code.
  • This file imports a number of widgets. Each widget is stored in its own sub-directory. All sub-directories contain an __init__.py file. These sub-directories are inside of a directory called ‘bin’, which is itself in the root dir
  • Some of these widgets need to have SIGNAL/SLOT links between them This is where I fall down.

So the file structure is:

 - main.py
 - bin/textEditor/__init__.py
 - bin/textEditor/plugin.py
 - bin/logWindow/__init__.py
 - bin/logWindow/plugin.py

The following code shows the problem. This code creates a very basic main window that contains a central QTextEdit() widget and a dockable QTextEdit() widget. All that happens is that when the text in the central widget is changed, the same text is shown in the dockable widget. The example works. But it does so by connecting the signal textChanged() in the bin/textEditor/plugin.py file that creates the central QTextEdit() with a function in main.py. I would like it to do exactly the same thing but connexted to the updateUi function in bin/textEditor/plugin.py

If anyone could shed some light on this, I would be hugely grateful. I’m sure it is simple. But direction to any tutorials that cover this or statements that I am doing it all very wrong are equally appreciated!. Thanks again for your time:

### main.py
import os
import sys
# Import PyQT modules
from PyQt4.QtCore import *
from PyQt4.QtGui import *

# Start the main class
class MainWindow(QMainWindow):

    # Initialise
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        # Name and size the main window
        self.setWindowTitle("EDITOR/LOG")
        self.resize(800, 600)

        import bin.logWindow.plugin as logWindow
        logWindow.create(self)

        import bin.textEditor.plugin as textEditor
        textEditor.create(self)

    def updateUi(self): 
        # I can connect to this function from within bin/textEditor/plugin.py (see 
        # below) but I want to connect to the function located in 
        # bin/textEditor/plugin.py instead
        text = self.editor.toPlainText()
        self.logWidget.setText(text)

# Run the app
def main():
    app = QApplication(sys.argv)
    form = MainWindow()
    form.show()
    app.exec_()
# Call main
main()

The code inside of the two plugin files is:

### bin/textEditor/plugin.py
# Import PyQT modules
from PyQt4.QtCore import *
from PyQt4.QtGui import *

def create(self):
    # Add a dockable widget
    self.logDockWidget = QDockWidget("Log", self)
    self.logDockWidget.setObjectName("LogDockWidget")
    self.logDockWidget.setAllowedAreas(Qt.LeftDockWidgetArea|
                                       Qt.RightDockWidgetArea)

    self.logWidget = QTextEdit()
    self.logDockWidget.setWidget(self.logWidget)
    self.addDockWidget(Qt.LeftDockWidgetArea, self.logDockWidget)

And

### bin/logWindow/plugin.py
Import PyQT modules
from PyQt4.QtCore import *
from PyQt4.QtGui import *

def create(self):

    # Create a text editing box
    self.editor = QTextEdit()

    # Add to main window
    self.setCentralWidget(self.editor)

    # connect text change to update log window. This is presumably what I need to 
    # change so that it connects to the function below instead of the on in main.py
    self.connect(self.editor, SIGNAL("textChanged()"), self.updateUi)

def updateUi(self):
    text = self.editor.toPlainText()
    self.logWidget.setText(text)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:49:29+00:00Added an answer on May 17, 2026 at 2:49 am

    For starters, is there a reason you’re using a very old version of the PyQt release document? The new one is: here

    There are a few things you are doing that are a bit unusual. Generally import statements in python are placed at the top of the file (to more easily see dependencies), but I assume you’re doing this to support a more generalized import system for plugins in the future.

    It seems like the basic problem is you’re trying to connect a signal source to a slot in another object, without storing that other object in a particular place. To do this you probably need to either make the connection in main, make a neutral “updateUi” slot that emits it’s own special signal that all the plugins are waiting for, or just keep a reference to those subobjects in main and be careful with the initialization order.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, thanks in advance for taking the time to read through this. I have
Thanks for taking the time to read this in advance. I am writing an
Thanks in advance for taking the time to read my question. I'm using MySQL
Thanks for taking the time to read this post. Finally built up enough courage
thanks in advance for taking the time to read through my question... /* Binary
Thanks for taking the time to read this! Well, this is what I am
Hello everybody and thanks for taking the time to read this ; I was
First off, thanks for taking the time to read this question. What a great
I know this is simple question but taking more time How to find first
Thanks for taking the time to read my question. I am looking for advice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.