[PyQt] Help with Login Dialog / QThread issues
bazwal at ftml.net
Sat Aug 6 18:14:26 BST 2011
On 05/08/11 17:46, Eric Frederich wrote:
> Any takers?
> On Thu, Jul 7, 2011 at 12:38 PM, Eric Frederich
> <eric.frederich at gmail.com> wrote:
>> I am trying to create a login dialog for my application.
>> Logging in can take a couple of seconds so I wanted to show a progress
>> bar during the login process.
>> I think that for my QProgressBar to animate during this time, I need
>> to log in on a different thread. Is this true?
>> So, below I have what I think is a working example.
>> Is there a better way to call QDialog's accept slot when the login
>> thread is finished than how I am doing it via functools.partial?
>> It seems a bit hacky.
>> from functools import partial
>> class LoginThread(QThread):
>> def __init__(self, username, password, parent=None):
>> super(LoginThread, self).__init__(parent)
>> self.username = username
>> self.password = password
>> def run(self):
>> class LoginDialog(QDialog, Ui_LoginDialog):
>> def __init__(self, *args, **kwargs):
>> super(LoginDialog, self).__init__(*args, **kwargs)
>> def accept(self):
>> self.lt = LoginThread(
>> self.connect(self.lt, SIGNAL('finished()'),
>> partial(QDialog.accept, self))
it's hard to tell from the limited code you've posted why you need to
override accept(). why not just create a handler for the clicked()
signal of the ok button (or whatever it is) and then connect the
thread's finished() signal directly to the dialog's accept() slot?
More information about the PyQt