[PyKDE] Newbie PyQt question

Jim Bublitz jbublitz at nwinternet.com
Tue Mar 8 17:06:23 GMT 2005


On Tuesday 08 March 2005 06:55, Andreas Pauley wrote:
> Hi all,
>
> I've started writing an app (point of sale) that needs to first show a
> login dialog (and succesfully authenticate a user) before showing the
>  main window.
>
> I've managed to do this, but my program fails to exit and return to the
> command prompt whenever the authentication failed and the main window
> never gets showed. The login window closes, but the command I use to
> start the app (python main.py) just hangs until I manually kill the
> proccess.
> The problem doesn't occur when the program exits after the main window is
> shown.
>
> I'm using QT 3.3.3 with PyQt 3.13.
>
> Regards,
> Andreas
>
> Here is a summary of my code.
> (This can also be downloaded from
> http://www.qbcon.com/downloads/python/qualitypos-minimal.tgz (12k))
>
> In main.py I do:
>      qapp = QApplication(sys.argv)
>
>  QObject.connect(qapp,SIGNAL("lastWindowClosed()"),qapp,SLOT("quit()"))
>  poswindow = QualityPOS()
>      qapp.setMainWidget(poswindow)
>      poswindow.login()
>      qapp.exec_loop()
>
> In the QualityPOS login() method:
> class QualityPOS(QualityPOSBase):
>      def login(self):
>          loginwindow = Login(self)
>          loginwindow.show()
>          loginwindow.exec_loop()
>
> The clicked signal of my login form connects to the authenticate() method
> in my Login class:
> class Login(LoginBase):
>      def __init__(self, poswindow):
>          LoginBase.__init__(self)
>          self.authenticated = False
>          self.poswindow = poswindow
>
>      def authenticate(self):
>          username=str(self.lnedUsername.text())
>          password=str(self.lnedPassword.text())
>          user=User.getUser(username, password)
>          if user:
>              self.poswindow.show()
>              self.authenticated = True
>          else:
>              self.authenticated = False
>              QMessageBox.warning(None,
>                  self.trUtf8("Login Incorrect"),
>                  self.trUtf8("""The user id and password you entered is
> incorrect."""),
>                  None,
>                  None,
>                  None,
>                  0, -1)
>          return self.authenticated

My guess is you can't do that - QDialog runs its own event loop and expects to 
pop back out to the main event loop, which doesn't exist until exec_loop() is 
called.  You could look at how Qt had coded QSplashScreen, but my guess is 
there's no event-loop type behavior there either, so it probably won't help 
much.

The easiest solution would be to make the authentication dialog a separate 
program and spawn/fork the main program on success, or not on failure. I'd 
think that would be a more secure solution too.

Jim




More information about the PyQt mailing list