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 8462265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:07:08+00:00 2026-06-10T14:07:08+00:00

Here is the code sample: class RunGui (QtGui.QMainWindow) def __init__(self, parent=None): … QtCore.Qobject.connect(self.ui.actionNew, QtCore.SIGNAL(triggered()),

  • 0

Here is the code sample:

class RunGui (QtGui.QMainWindow)

    def __init__(self, parent=None):

        ...
        QtCore.Qobject.connect(self.ui.actionNew, QtCore.SIGNAL("triggered()"), self.new_select)
        ...


    def normal_output_written(self, qprocess):
        self.ui.text_edit.append("caught outputReady signal") #works
        self.ui.text_edit.append(str(qprocess.readAllStandardOutput())) # doesn't work


    def new_select(self):
        ...
        dialog_np = NewProjectDialog()
        dialog_np.exec_()
        if dialog_np.is_OK:
            section = dialog_np.get_section()
            project = dialog_np.get_project()
            ...
            np = NewProject()
            np.outputReady.connect(lambda: self.normal_output_written(np.qprocess))
            np.errorReady.connect(lambda: self.error_output_written(np.qprocess))
            np.inputNeeded.connect(lambda: self.input_from_line_edit(np.qprocess))
            np.params = partial(np.create_new_project, section, project, otherargs)
            np.start()

class NewProject(QtCore.QThread):

    outputReady = QtCore.pyqtSignal(object)
    errorReady = QtCore.pyqtSignal(object)
    inputNeeded = QtCore.pyqtSignal(object)
    params = None
    message = ""

    def __init__(self):
        super(NewProject, self).__init__()
        self.qprocess = QtCore.QProcess()
        self.qprocess.moveToThread(self)
        self._inputQueue = Queue()

    def run(self):
        self.params()

    def create_new_project(self, section, project, otherargs):
        ...
        # PyDev for some reason skips the breakpoints inside the thread
        self.qprocess.start(command)
        self.qprocess.waitForReadyRead()
        self.outputReady.emit(self.qprocess) # works - I'm getting signal in RunGui.normal_output_written()
        print(str(self.qprocess.readAllStandardOutput())) # prints empty line
        .... # other actions inside the method requiring "command" to finish properly.

The idea is beaten to death – get the GUI to run scripts and communicate with the processes. The challenge in this particular example is that the script started in QProcess as command runs an app, that requires user input (confirmation) along the way. Therefore I have to be able to start the script, get all output and parse it, wait for the question to appear in the output and then communicate back the answer, allow it to finish and only then to proceed further with other actions inside create_new_project()

  • 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-06-10T14:07:10+00:00Added an answer on June 10, 2026 at 2:07 pm

    I don’t know if this will fix your overall issue, but there are a few design issues I see here.

    1. You are passing around the qprocess between threads instead of just emitting your custom signals with the results of the qprocess
    2. You are using class-level attributes that should probably be instance attributes

    Technically you don’t even need the QProcess, since you are running it in your thread and actively using blocking calls. It could easily be a subprocess.Popen…but anyways, I might suggest changes like this:

    class RunGui (QtGui.QMainWindow)
        
        ...
    
        def normal_output_written(self, msg):
            self.ui.text_edit.append(msg) 
    
        def new_select(self):
            ...
                np = NewProject()
                np.outputReady.connect(self.normal_output_written)
                np.params = partial(np.create_new_project, section, project, otherargs)
                np.start()
    
    class NewProject(QtCore.QThread):
    
        outputReady = QtCore.pyqtSignal(object)
        errorReady = QtCore.pyqtSignal(object)
        inputNeeded = QtCore.pyqtSignal(object)
    
        def __init__(self):
            super(NewProject, self).__init__()
    
            self._inputQueue = Queue()
            self.params = None
    
        def run(self):
            self.params()
    
        def create_new_project(self, section, project, otherargs):
            ...
            qprocess = QtCore.QProcess()
            qprocess.start(command)
            if not qprocess.waitForStarted():
                # handle a failed command here
                return
    
            if not qprocess.waitForReadyRead():
                # handle a timeout or error here
                return
    
            msg = str(self.qprocess.readAllStandardOutput())
            self.outputReady.emit(msg) 
    

    Don’t pass around the QProcess. Just emit the data. And create it from within the threads method so that it is automatically owned by that thread. Your outside classes should really not have any knowledge of that QProcess object. It doesn’t even need to be a member attribute since its only needed during the operation.

    Also make sure you are properly checking that your command both successfully started, and is running and outputting data.

    Update

    To clarify some problems you might be having (per the comments), I wanted to suggest that QProcess might not be the best option if you need to have interactive control with processes that expect periodic user input. It should work find for running scripts that just produce output from start to finish, though really using subprocess would be much easier. For scripts that need user input over time, your best bet may be to use pexpect. It allows you to spawn a process, and then watch for various patterns that you know will indicate the need for input:

    foo.py

    import time
    
    i = raw_input("Please enter something: ")
    print "Output:", i
    time.sleep(.1)
    print "Another line"
    time.sleep(.1)
    print "Done"
    

    test.py

    import pexpect
    import time
    
    child = pexpect.spawn("python foo.py")
    child.setecho(False)
    
    ret = -1
    while ret < 0:
        time.sleep(.05)
        ret = child.expect("Please enter something: ")
    
    child.sendline('FOO')
    while True:
        line = child.readline()
        if not line:
            break
        print line.strip()
    
    # Output: FOO
    # Another line
    # Done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the sample code: class TestAO { int[] x; public TestAO () { this.x
Here's a sample code: #include <stack> #include <cstddef> template <std::size_t N, template <class> class
Here's my code package net.sourceforge.jwebunit.sample; import net.sourceforge.jwebunit.WebTestCase; public class JWebUnitSearchExample extends WebTestCase { public
Here's sample model classes, which being use with Entity Framework Code First: public class
here is my c++ code : class Sample { public: int *ptr; Sample(int i)
Here is the sample code: class Class1 { string a; public Class1(string over) :
I'm wondering the best form for my constructors. Here is some sample code: class
Here is a code sample from the ruby pickaxe book: Class VowelFinder include Enumerable
I've got a (relatively) brief code sample here. #include <type_traits> template<typename T> class function;
this is just a sample code class parent{ //abstact class //pure virtual function virtual

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.