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. QPushButton exit my application when clicked
Forum Updated to NodeBB v4.3 + New Features

QPushButton exit my application when clicked

Scheduled Pinned Locked Moved Unsolved Qt for Python
12 Posts 3 Posters 1.6k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    LT-K101
    wrote on 22 Jun 2021, 05:19 last edited by
    #1

    When i click on the QPushButtons i have created it closes my application. Below is my code, I would be glad if i get a helping hand. Thanks .

    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
    import sys

    import sqlite3

    from PyQt5.uic import loadUiType

    ui,_ = loadUiType('Conf_Reg_Manager.ui')

    class MainApp(QMainWindow, ui):
    def init(self, parent=None):
    QMainWindow.init(self)
    super(MainApp,self).init(parent)
    self.setupUi(self)
    self.Handle_UI_Changes()
    self.Handle_Buttons()

              ############################################################################
              ############### FUNCTIONS FOR UI CHANGES AND BUTTONS EFFECT ################
    
    def Handle_UI_Changes(self):
        self.Hide_Themes()
        self.tabWidget.tabBar().setVisible(False)
    
    
    
    
    
    
    def Handle_Buttons(self):
        self.pushButton_4.clicked.connect(self.Show_Themes)
        self.pushButton_20.clicked.connect(self.Hide_Themes)
    
    
    
        self.pushButton_6.clicked.connect(self.Open_Daily_Operations_Tab)
        self.pushButton_23.clicked.connect(self.Open_Infromation_Details_Tab)
        self.pushButton_2.clicked.connect(self.Open_Users_Tab)
        self.pushButton_3.clicked.connect(self.Open_Settings_Tab)
    
    
    
        self.pushButton.clicked.connect(self.GET_DATA)
    

    ############ CONNECT TO SQLITE3 DATABASE AND FILL GUI TABLE WITH DATA

    def GET_DATA(self):
    
        db=sqlite3.connect('Conf_Registry_Storage')
        cursor=db.cursor()
    
    
        command=''' SELECT * from Daily_Operations '''
    
        result=cursor.execute(command)
    
    
        self.tableWidget_6.setRowCount(0)
    
    
        for row_number, row_data in enumerate(result):
            self.tableWidget_6.insertRow(row_number)
            for column_number, data in enumerate(row_data):
                self.tableWidget_6.setItem(row_number, column_number, QTableWidgetItem(str(data)))
    
    
    
        ##############################################
        ########## SHOW AND HIDE THEMES ######################
    
    
    
    def Show_Themes(self):
        self.groupBox_7.show()
    
    
    def Hide_Themes(self):
        self.groupBox_7.hide()
    
    
    
    
     ##############################################
     ########## OPENING TABS ######################
    
    
    def Open_Daily_Operations_Tab(self):
        self.tabWidget.setCurrentIndex(0)
    
    
    def Open_Infromation_Details_Tab(self):
        self.tabWidget.setCurrentIndex(1)
    
    
    def Open_Users_Tab(self):
        self.tabWidget.setCurrentIndex(2)
    
    
    def Open_Settings_Tab(self):
        self.tabWidget.setCurrentIndex(3)
    

    def main():
    app = QApplication(sys.argv)
    window = MainApp()
    window.show()
    app.exec_()

    if name == 'main':
    main()

    J 1 Reply Last reply 22 Jun 2021, 08:48
    0
    • L LT-K101
      22 Jun 2021, 05:19

      When i click on the QPushButtons i have created it closes my application. Below is my code, I would be glad if i get a helping hand. Thanks .

      from PyQt5.QtCore import *
      from PyQt5.QtGui import *
      from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
      import sys

      import sqlite3

      from PyQt5.uic import loadUiType

      ui,_ = loadUiType('Conf_Reg_Manager.ui')

      class MainApp(QMainWindow, ui):
      def init(self, parent=None):
      QMainWindow.init(self)
      super(MainApp,self).init(parent)
      self.setupUi(self)
      self.Handle_UI_Changes()
      self.Handle_Buttons()

                ############################################################################
                ############### FUNCTIONS FOR UI CHANGES AND BUTTONS EFFECT ################
      
      def Handle_UI_Changes(self):
          self.Hide_Themes()
          self.tabWidget.tabBar().setVisible(False)
      
      
      
      
      
      
      def Handle_Buttons(self):
          self.pushButton_4.clicked.connect(self.Show_Themes)
          self.pushButton_20.clicked.connect(self.Hide_Themes)
      
      
      
          self.pushButton_6.clicked.connect(self.Open_Daily_Operations_Tab)
          self.pushButton_23.clicked.connect(self.Open_Infromation_Details_Tab)
          self.pushButton_2.clicked.connect(self.Open_Users_Tab)
          self.pushButton_3.clicked.connect(self.Open_Settings_Tab)
      
      
      
          self.pushButton.clicked.connect(self.GET_DATA)
      

      ############ CONNECT TO SQLITE3 DATABASE AND FILL GUI TABLE WITH DATA

      def GET_DATA(self):
      
          db=sqlite3.connect('Conf_Registry_Storage')
          cursor=db.cursor()
      
      
          command=''' SELECT * from Daily_Operations '''
      
          result=cursor.execute(command)
      
      
          self.tableWidget_6.setRowCount(0)
      
      
          for row_number, row_data in enumerate(result):
              self.tableWidget_6.insertRow(row_number)
              for column_number, data in enumerate(row_data):
                  self.tableWidget_6.setItem(row_number, column_number, QTableWidgetItem(str(data)))
      
      
      
          ##############################################
          ########## SHOW AND HIDE THEMES ######################
      
      
      
      def Show_Themes(self):
          self.groupBox_7.show()
      
      
      def Hide_Themes(self):
          self.groupBox_7.hide()
      
      
      
      
       ##############################################
       ########## OPENING TABS ######################
      
      
      def Open_Daily_Operations_Tab(self):
          self.tabWidget.setCurrentIndex(0)
      
      
      def Open_Infromation_Details_Tab(self):
          self.tabWidget.setCurrentIndex(1)
      
      
      def Open_Users_Tab(self):
          self.tabWidget.setCurrentIndex(2)
      
      
      def Open_Settings_Tab(self):
          self.tabWidget.setCurrentIndex(3)
      

      def main():
      app = QApplication(sys.argv)
      window = MainApp()
      window.show()
      app.exec_()

      if name == 'main':
      main()

      J Offline
      J Offline
      JonB
      wrote on 22 Jun 2021, 08:48 last edited by
      #2

      @LT-K101
      Run it in a debugger and see where it crashes/how far you get. Or put print() statements in.

      L 1 Reply Last reply 23 Jun 2021, 05:17
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on 22 Jun 2021, 19:45 last edited by
        #3

        Hi and welcome to devnet,

        Which buttons triggers that ?

        By the way, please use coding tags around your code (the </> button) so it makes it easier to read.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        L 1 Reply Last reply 23 Jun 2021, 05:34
        0
        • J JonB
          22 Jun 2021, 08:48

          @LT-K101
          Run it in a debugger and see where it crashes/how far you get. Or put print() statements in.

          L Offline
          L Offline
          LT-K101
          wrote on 23 Jun 2021, 05:17 last edited by
          #4

          @JonB I used pycharm community edition to run the program and i get no error message just that the application exits when i click on a refresh button to load data from sqlite3 database

          J 1 Reply Last reply 23 Jun 2021, 06:53
          0
          • SGaistS SGaist
            22 Jun 2021, 19:45

            Hi and welcome to devnet,

            Which buttons triggers that ?

            By the way, please use coding tags around your code (the </> button) so it makes it easier to read.

            L Offline
            L Offline
            LT-K101
            wrote on 23 Jun 2021, 05:34 last edited by
            #5

            @SGaist when i write a function for a button to either insert data into sqlite3 DB or load data from sqlite3 DB.

            1 Reply Last reply
            0
            • L LT-K101
              23 Jun 2021, 05:17

              @JonB I used pycharm community edition to run the program and i get no error message just that the application exits when i click on a refresh button to load data from sqlite3 database

              J Offline
              J Offline
              JonB
              wrote on 23 Jun 2021, 06:53 last edited by
              #6

              @LT-K101
              Did you step through in the debugger to watch which statements get executed and where it crashes? Or at least put in print() statements?

              L 1 Reply Last reply 24 Jun 2021, 20:23
              0
              • J JonB
                23 Jun 2021, 06:53

                @LT-K101
                Did you step through in the debugger to watch which statements get executed and where it crashes? Or at least put in print() statements?

                L Offline
                L Offline
                LT-K101
                wrote on 24 Jun 2021, 20:23 last edited by
                #7

                @JonB I did insert the print () statement and it did work perfectly. I think its the database connection.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 24 Jun 2021, 20:25 last edited by
                  #8

                  Out of curiosity, why not use Qt's SQL module ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  L 1 Reply Last reply 13 Jul 2021, 19:40
                  0
                  • SGaistS SGaist
                    24 Jun 2021, 20:25

                    Out of curiosity, why not use Qt's SQL module ?

                    L Offline
                    L Offline
                    LT-K101
                    wrote on 13 Jul 2021, 19:40 last edited by
                    #9

                    @SGaist I have not tried Qtsql but I'm familiar with sqlite3.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 13 Jul 2021, 20:17 last edited by
                      #10

                      Then as asked before: which exact method makes your application crash ?

                      Which exception do you get ?

                      Did you try to use pdb to see what is going on ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        LT-K101
                        wrote on 14 Jul 2021, 05:10 last edited by
                        #11

                        @SGaist now i can run and display my application but the syntax for connecting to the db within the PyQT5 GUI class is my problem now.

                        J 1 Reply Last reply 14 Jul 2021, 07:54
                        0
                        • L LT-K101
                          14 Jul 2021, 05:10

                          @SGaist now i can run and display my application but the syntax for connecting to the db within the PyQT5 GUI class is my problem now.

                          J Offline
                          J Offline
                          JonB
                          wrote on 14 Jul 2021, 07:54 last edited by
                          #12

                          @LT-K101
                          PyQt5 does not come with its own Python documentation for Qt methods. They expect you to look at the standard C++ docs and adapt to Python. PySide does give some documentation, and should be same for PyQt5. So you should read through e.g. https://doc.qt.io/qtforpython-5/PySide2/QtSql/QSqlDatabase.html#detailed-description where there are Python examples of using QSqlDatabase, etc.

                          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