Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to get the returned value?
Forum Updated to NodeBB v4.3 + New Features

How to get the returned value?

Scheduled Pinned Locked Moved Solved Qt for Python
28 Posts 3 Posters 6.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _jao_victor_
    wrote on last edited by _jao_victor_
    #19

    Ok @jsulm and @JonB, so far I understood correctly, I did the tests and got the expected result, however, what if the buttons are not the ones from QDialog, but one that I implemented myself? The Cancel and OK buttons send the signals automatically when they are pressed, so how do I make my buttons (login and register) send their signals when they are pressed?

    esseaquivai.pnga

    JonBJ 1 Reply Last reply
    0
    • _ _jao_victor_

      Ok @jsulm and @JonB, so far I understood correctly, I did the tests and got the expected result, however, what if the buttons are not the ones from QDialog, but one that I implemented myself? The Cancel and OK buttons send the signals automatically when they are pressed, so how do I make my buttons (login and register) send their signals when they are pressed?

      esseaquivai.pnga

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #20

      @_jao_victor_
      Looks OK. Sorry, is there a question here?

      _ 1 Reply Last reply
      0
      • JonBJ JonB

        @_jao_victor_
        Looks OK. Sorry, is there a question here?

        _ Offline
        _ Offline
        _jao_victor_
        wrote on last edited by
        #21

        @JonB yes i rewrote the text to explain it better, sorry.

        JonBJ 1 Reply Last reply
        0
        • _ _jao_victor_

          @JonB yes i rewrote the text to explain it better, sorry.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #22

          @_jao_victor_

          connect(loginButton, &QPushButton::clicked, accept);
          connect(cancelButton, &QPushButton::clicked, reject);
          

          You'll have to think a bit more carefully about the Register button. It does not do the same thing as the Login button, i.e. it does/should not cause the dialog to exit with "success" back to the main program for the user to continue into the main window.

          That's for you to figure out what you want to do.

          QDialog does not have to exit with only accept() or reject(). They use void QDialog::done(int r), and you can do the same with as many different r values as you please. That value is the return result when you go int result = dialog.exec().

          _ 1 Reply Last reply
          2
          • JonBJ JonB

            @_jao_victor_

            connect(loginButton, &QPushButton::clicked, accept);
            connect(cancelButton, &QPushButton::clicked, reject);
            

            You'll have to think a bit more carefully about the Register button. It does not do the same thing as the Login button, i.e. it does/should not cause the dialog to exit with "success" back to the main program for the user to continue into the main window.

            That's for you to figure out what you want to do.

            QDialog does not have to exit with only accept() or reject(). They use void QDialog::done(int r), and you can do the same with as many different r values as you please. That value is the return result when you go int result = dialog.exec().

            _ Offline
            _ Offline
            _jao_victor_
            wrote on last edited by _jao_victor_
            #23

            @JonB I think I'm almost there :). I've been researching more and seeing the differences between
            Build Time and Runtime and more, The single inheritance approach and The multiple inheritance approach however, as I am still a beginner I was a bit in doubt in which my app fits, I think in Compilation time and multiple inheritance, right?

            This is my current code:

            from PyQt5 import uic, QtWidgets
            from PyQt5.QtWidgets import QDialog
            from views.ui.login.telaLogin import Ui_Dialog
            import sys
            from control.exception_login import verification_login_user
            
            class ViewLogin(QDialog):
                def __init__(self):
                    super().__init__()
                    self.viewlogin = Ui_Dialog()
                    self.viewlogin.setupUi(self)
            
                    self.viewlogin.button_login.clicked.connect(self.login)
            
                def login(self):
            
                    self.login = self.viewlogin.login_login.text() 
                    self.password = self.viewlogin.login_password.text()
            
                    erro =  verification_login_user(self.login, self.password)
                
                    if (erro == False):
                        self.close()
                        sessao_user = (self.login, self.senha) 
                        #self.done(r) # I understand its functionality # PROBLEM
                        #return (sessao_user) # PROBLEM
                        self.accept() # The problem would end here if I didn't need the variable sessao_user
                         
                    elif(erro == True):
                        self.viewlogin.login_login.setText('')
                        self.viewlogin.login_password.setText('')
                        
            
            app = QtWidgets.QApplication([])
            
            w = ViewLogin()
            result = w.exec_()
            
            print(result)  # desired result = (' login', 'password') 
            # real result = 1 
            
            sys.exit(app.exec_())
            

            But unfortunately I saw that done () only takes numbers as a parameter and does not allow another type, and the return doesn't work here either, so I still don't have the sessao_user variable in main.py because I need to pass it to the main window.

            JonBJ 1 Reply Last reply
            0
            • _ _jao_victor_

              @JonB I think I'm almost there :). I've been researching more and seeing the differences between
              Build Time and Runtime and more, The single inheritance approach and The multiple inheritance approach however, as I am still a beginner I was a bit in doubt in which my app fits, I think in Compilation time and multiple inheritance, right?

              This is my current code:

              from PyQt5 import uic, QtWidgets
              from PyQt5.QtWidgets import QDialog
              from views.ui.login.telaLogin import Ui_Dialog
              import sys
              from control.exception_login import verification_login_user
              
              class ViewLogin(QDialog):
                  def __init__(self):
                      super().__init__()
                      self.viewlogin = Ui_Dialog()
                      self.viewlogin.setupUi(self)
              
                      self.viewlogin.button_login.clicked.connect(self.login)
              
                  def login(self):
              
                      self.login = self.viewlogin.login_login.text() 
                      self.password = self.viewlogin.login_password.text()
              
                      erro =  verification_login_user(self.login, self.password)
                  
                      if (erro == False):
                          self.close()
                          sessao_user = (self.login, self.senha) 
                          #self.done(r) # I understand its functionality # PROBLEM
                          #return (sessao_user) # PROBLEM
                          self.accept() # The problem would end here if I didn't need the variable sessao_user
                           
                      elif(erro == True):
                          self.viewlogin.login_login.setText('')
                          self.viewlogin.login_password.setText('')
                          
              
              app = QtWidgets.QApplication([])
              
              w = ViewLogin()
              result = w.exec_()
              
              print(result)  # desired result = (' login', 'password') 
              # real result = 1 
              
              sys.exit(app.exec_())
              

              But unfortunately I saw that done () only takes numbers as a parameter and does not allow another type, and the return doesn't work here either, so I still don't have the sessao_user variable in main.py because I need to pass it to the main window.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #24

              @_jao_victor_
              Indeed the accept/reject/done() only tell the caller what button the user to exit the modal dialog. That is all you actually return from it. But there is nothing to stop the caller still querying what is in the dialog's widgets:

              result = viewlogin.exec()
              if not result:
                  sys.exit(1)
              username = viewlogin.login_login.text()
              

              If you want to do it via your sessao_user you will have to use Python's global to access that. Or, you could wrap it up with some method from the dialog:

              class ViewLogin(QDialog):
                  def sessao_user(self):
                      return (self.login, self.senha)
              
              result = viewlogin.exec()
              if not result:
                  sys.exit(1)
              sessao_user = viewlogin.sessao_user()
              

              In your def login() do not do self.close(). self.accept/reject/done() close the dialog.

              _ 1 Reply Last reply
              0
              • JonBJ JonB

                @_jao_victor_
                Indeed the accept/reject/done() only tell the caller what button the user to exit the modal dialog. That is all you actually return from it. But there is nothing to stop the caller still querying what is in the dialog's widgets:

                result = viewlogin.exec()
                if not result:
                    sys.exit(1)
                username = viewlogin.login_login.text()
                

                If you want to do it via your sessao_user you will have to use Python's global to access that. Or, you could wrap it up with some method from the dialog:

                class ViewLogin(QDialog):
                    def sessao_user(self):
                        return (self.login, self.senha)
                
                result = viewlogin.exec()
                if not result:
                    sys.exit(1)
                sessao_user = viewlogin.sessao_user()
                

                In your def login() do not do self.close(). self.accept/reject/done() close the dialog.

                _ Offline
                _ Offline
                _jao_victor_
                wrote on last edited by
                #25

                @JonB Fiddled, thank you. And thanks to @jsulm too. But clarify one last question, as the documentation is in C ++, I didn't understand it very well, but is my app running time? Do you use the multiple or single inheritance approach?

                JonBJ 1 Reply Last reply
                0
                • _ _jao_victor_

                  @JonB Fiddled, thank you. And thanks to @jsulm too. But clarify one last question, as the documentation is in C ++, I didn't understand it very well, but is my app running time? Do you use the multiple or single inheritance approach?

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #26

                  @_jao_victor_ said in How to get the returned value?:

                  I didn't understand it very well, but is my app running time?

                  I don't know what this means :)

                  Do you use the multiple or single inheritance approach?

                  Neither of these seems to be relevant to what you have been asking about :)

                  _ 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @_jao_victor_ said in How to get the returned value?:

                    I didn't understand it very well, but is my app running time?

                    I don't know what this means :)

                    Do you use the multiple or single inheritance approach?

                    Neither of these seems to be relevant to what you have been asking about :)

                    _ Offline
                    _ Offline
                    _jao_victor_
                    wrote on last edited by
                    #27

                    @JonB sorry, I don't speak your language, but the question is does my app followBuild Time or Runtime?

                    JonBJ 1 Reply Last reply
                    0
                    • _ _jao_victor_

                      @JonB sorry, I don't speak your language, but the question is does my app followBuild Time or Runtime?

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #28

                      @_jao_victor_

                      viewlogin = uic.loadUi('./views/ui/login/viewLogin.ui') 
                      mainview =  uic.loadUi('./views/ui/main/mainview.ui')
                      

                      Since you are loading a .ui file at runtime you are following the pattern from Run Time Form Processing.

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved