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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:23:56+00:00 2026-06-09T04:23:56+00:00

I nearly finished my application, when the customer asked if I could implement some

  • 0

I nearly finished my application, when the customer asked if I could implement some kind of login form on application startup.

So far I have designed the UI, and tinkered about the actual execution. Username and password are irrelevant for now.

class Login(QtGui.QDialog):
    def __init__(self,parent=None):
        QtGui.QWidget.__init__(self,parent)
        self.ui=Ui_dlgLogovanje()
        self.ui.setupUi(self)

        QtCore.QObject.connect(self.ui.buttonLogin, QtCore.SIGNAL("clicked()"), self.doLogin)

    def doLogin(self):
        name = str(self.ui.lineKorisnik.text())
        passwd = str(self.ui.lineSifra.text())
        if name == "john" and passwd =="doe":
            self.runIt()
        else:
            QtGui.QMessageBox.warning(self, 'Greška',
        "Bad user or password", QtGui.QMessageBox.Ok)           

    def runIt(self):
        myprogram = Window()        
        myprogram.showMaximized() #myprogram is

class Window(QtGui.QMainWindow):
    def __init__(self,parent=None):
        QtGui.QWidget.__init__(self,parent)
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)


if __name__=="__main__":
    program = QtGui.QApplication(sys.argv)
    myprogram = Window()
    if Login().exec_() == QtGui.QDialog.Accepted:       
        sys.exit(program.exec_())

Login form is shown. If correct username and password are entered, then main window is shown and working. But, the login form stays active, and if I close it, the main window will also close.

  • 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-09T04:23:58+00:00Added an answer on June 9, 2026 at 4:23 am

    A QDialog has its own event loop, so it can be run separately from the main application.

    You just need to check the dialog’s return code to decide whether the main application should be run or not.

    Example code (PyQt5):

    from PyQt5 import QtWidgets
    # from mainwindow import Ui_MainWindow
    
    class Login(QtWidgets.QDialog):
        def __init__(self, parent=None):
            super(Login, self).__init__(parent)
            self.textName = QtWidgets.QLineEdit(self)
            self.textPass = QtWidgets.QLineEdit(self)
            self.buttonLogin = QtWidgets.QPushButton('Login', self)
            self.buttonLogin.clicked.connect(self.handleLogin)
            layout = QtWidgets.QVBoxLayout(self)
            layout.addWidget(self.textName)
            layout.addWidget(self.textPass)
            layout.addWidget(self.buttonLogin)
    
        def handleLogin(self):
            if (self.textName.text() == 'foo' and
                self.textPass.text() == 'bar'):
                self.accept()
            else:
                QtWidgets.QMessageBox.warning(
                    self, 'Error', 'Bad user or password')
    
    class Window(QtWidgets.QMainWindow):
        def __init__(self, parent=None):
            super(Window, self).__init__(parent)
            # self.ui = Ui_MainWindow()
            # self.ui.setupUi(self)
    
    if __name__ == '__main__':
    
        import sys
        app = QtWidgets.QApplication(sys.argv)
        login = Login()
    
        if login.exec_() == QtWidgets.QDialog.Accepted:
            window = Window()
            window.show()
            sys.exit(app.exec_())
    

    Example code (PyQt4):

    from PyQt4 import QtGui
    # from mainwindow import Ui_MainWindow
    
    class Login(QtGui.QDialog):
        def __init__(self, parent=None):
            super(Login, self).__init__(parent)
            self.textName = QtGui.QLineEdit(self)
            self.textPass = QtGui.QLineEdit(self)
            self.buttonLogin = QtGui.QPushButton('Login', self)
            self.buttonLogin.clicked.connect(self.handleLogin)
            layout = QtGui.QVBoxLayout(self)
            layout.addWidget(self.textName)
            layout.addWidget(self.textPass)
            layout.addWidget(self.buttonLogin)
    
        def handleLogin(self):
            if (self.textName.text() == 'foo' and
                self.textPass.text() == 'bar'):
                self.accept()
            else:
                QtGui.QMessageBox.warning(
                    self, 'Error', 'Bad user or password')
    
    class Window(QtGui.QMainWindow):
        def __init__(self, parent=None):
            super(Window, self).__init__(parent)
            # self.ui = Ui_MainWindow()
            # self.ui.setupUi(self)    
    
    if __name__ == '__main__':
    
        import sys
        app = QtGui.QApplication(sys.argv)
        login = Login()
    
        if login.exec_() == QtGui.QDialog.Accepted:
            window = Window()
            window.show()
            sys.exit(app.exec_())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm nearly finished with writing my first iOS application, but I ran into a
I am nearly finished with the development of an Android application. But there seems
I have nearly finished a free spellchecker library for Windows Mobile, and there are
I am nearly finished a web application. I need to test it and find
I have nearly finished my app but still have to make sure landscape orientations
I have an app that is nearly finished but encountered an annoying problem. In
I'm nearly finished with this project but I have been beating my head against
I've nearly finished rewriting (with some new features) my Symfony (left a bit bad
I have nearly finished writing this code: http://jsfiddle.net/2Jkk9/11/ but I can't figure out how
Im new at writing iOS apps, and have nearly finished writing my first game.

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.