Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. QSql refresh()?
Forum Updated to NodeBB v4.3 + New Features

QSql refresh()?

Scheduled Pinned Locked Moved Solved Language Bindings
python
18 Posts 4 Posters 5.3k Views 3 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.
  • the_T the_

    Same question as this?
    https://forum.qt.io/topic/75371/is-there-any-function-in-pyqt4-that-refresh-data-table

    ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #3

    @the_ yes i follow what you said on that thread but is not refreshing when i click submit

    1 Reply Last reply
    0
    • the_T the_

      Same question as this?
      https://forum.qt.io/topic/75371/is-there-any-function-in-pyqt4-that-refresh-data-table

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #4

      @the_ i want to display the query when i clicked the button submit without rerunning the program

      1 Reply Last reply
      0
      • the_T Offline
        the_T Offline
        the_
        wrote on last edited by
        #5

        How do you display the data when you click the submit button?

        -- No support in PM --

        ? 4 Replies Last reply
        0
        • the_T the_

          How do you display the data when you click the submit button?

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #6

          @the_
          else:
          self.con = mysql.connector.connect(user="root",password="admingelo",host="localhost",database="incoming_mac")
          self.manager = self.con.cursor()
          self.insert_this_data = ("""INSERT INTO incoming_mac_records(DATE_RECEIVED,RECEIVED_BY,DELIVERED_BY,INVOICE_NUMBER) VALUES('%s','%s','%s',%s)"""%(DATE_RECEIVED,RECEIVED_BY,DELIVERED_BY,str(INVOICE)))
          self.manager.execute(self.insert_this_data)
          self.con.commit()
          self.con.close()
          print "Okay na bes!"

                  self.projectModel = QSqlQueryModel()
                  self.projectModel.setQuery("select * from incoming_mac_records",self.db)
          
          1 Reply Last reply
          0
          • the_T the_

            How do you display the data when you click the submit button?

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #7

            @the_
            self.db = QSqlDatabase.addDatabase("QMYSQL")

                self.db.setHostName("localhost")
                self.db.setDatabaseName("incoming_mac")
                self.db.setUserName("root")
                self.db.setPassword("admingelo")
                self.db.open()
            
                self.projectModel = QSqlQueryModel()
                self.projectModel.setQuery("select * from incoming_mac_records",self.db)
            
                self.projectView = QTableView(self)
                self.projectView.setModel(self.projectModel)
                self.projectView.resizeColumnsToContents()
            
                self.projectView.setGeometry(250,10,940,680)
            
            1 Reply Last reply
            0
            • the_T the_

              How do you display the data when you click the submit button?

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #8

              @the_ sorry for the long codes i am new to programming

              import sys
              import os
              from PyQt4.QtGui import *
              from PyQt4.QtCore import *
              from PyQt4.QtSql import *
              from PyQt4 import QtGui,QtCore
              import mysql.connector

              class Window(QtGui.QMainWindow):
              def init(self):
              super(Window, self).init()
              self.setGeometry(50,50,1200,700)
              self.setWindowTitle("Inventory and Monitoring System")
              self.setWindowIcon(QtGui.QIcon('Pictures/delta.png'))
              QApplication.setStyle(QStyleFactory.create('Cleanlooks'))

                  self.db = QSqlDatabase.addDatabase("QMYSQL")
              
                  self.db.setHostName("localhost")
                  self.db.setDatabaseName("incoming_mac")
                  self.db.setUserName("root")
                  self.db.setPassword("admingelo")
                  self.db.open()
              
                  self.projectModel = QSqlQueryModel()
                  self.projectModel.setQuery("select * from incoming_mac_records",self.db)
              
                  self.projectView = QTableView(self)
                  self.projectView.setModel(self.projectModel)
                  self.projectView.resizeColumnsToContents()
              
                  self.projectView.setGeometry(250,10,940,680)
                  
                          
                  self.buttons()
              
              def buttons(self):
                  #Search function
                  self.search = QLineEdit(self)
                  self.search.resize(150,25)
                  self.searchLabel = QLabel("Search",self)
                  self.searchLabel.move(10,10)
                  self.search.move(90,10)
                  self.searchbtn = QtGui.QPushButton("SEARCH",self)
                  self.searchbtn.clicked.connect(self.searchFunction)
                  self.searchbtn.resize(self.searchbtn.minimumSizeHint())
                  self.searchbtn.move(160,40)
                  #End of search function
              
                  #start input 1
                  self.Date_received = QtGui.QLineEdit(self)
                  self.Date_received.resize(150,25)
                  self.InputLabel = QtGui.QLabel("Date received",self)
                  self.Date_received.move(90,100)
                  self.InputLabel.move(10,99)
                  #end Input 1
              
                  #start input 2
                  self.query = QSqlQuery("SELECT name FROM names_delta")
                  self.Received_by = QComboBox(self)
                  self.Received_by.currentIndexChanged.connect(self.inputFunction)
                  self.Received_by.resize(150,25)
                  self.Input2Label = QLabel("Received by",self)
                  self.Input2Label.move(10,130)
                  self.Received_by.move(90,130)
                  
                  while(self.query.next()):
                      self.Received_by.addItem(self.query.value(0).toString())
                  self.DATA_COMBOBOX = self.Received_by.currentText()
                  #end input 2
              
                  #start input 3
                  self.Delivered_by = QtGui.QLineEdit(self)
                  self.Delivered_by.resize(150,25)
                  self.Input3Label = QtGui.QLabel("Delivered by",self)
                  self.Input3Label.move(10,160)
                  self.Delivered_by.move(90,160)
                  #end input 3
              
                  #start input 4
                  self.Invoice = QtGui.QLineEdit(self)
                  self.Invoice.resize(150,25)
                  self.Input4Label = QtGui.QLabel("Invoice #",self)
                  self.Input4Label.move(10,190)
                  self.Invoice.move(90,190)
                  #end input 4
              
                  #start input 5
                  self.Purchase_order = QtGui.QLineEdit(self)
                  self.Purchase_order.resize(150,25)
                  self.Input5Label = QtGui.QLabel("Purchase Order",self)
                  self.Input5Label.move(10,220)
                  self.Purchase_order.move(90,220)
                  #end input 5
              
                  #start input 6
                  self.Model = QtGui.QLineEdit(self)
                  self.Model.resize(150,25)
                  self.Input6Label = QtGui.QLabel("Model",self)
                  self.Input6Label.move(10,250)
                  self.Model.move(90,250)
                  #end input 6
              
                  #start input 7
                  self.Specification = QtGui.QLineEdit(self)
                  self.Specification.resize(150,25)
                  self.Input7Label = QtGui.QLabel("Specification",self)
                  self.Input7Label.move(10,280)
                  self.Specification.move(90,280)
                  #end input 7
              
                  #start input 8
                  self.Quantity = QtGui.QLineEdit(self)
                  self.Quantity.resize(150,25)
                  self.Input8Label = QtGui.QLabel("Quantity",self)
                  self.Input8Label.move(10,310)
                  self.Quantity.move(90,310)
                  #end input 8
              
                  #start input 9
                  self.Serial = QtGui.QLineEdit(self)
                  self.Serial.resize(150,25)
                  self.Input9Label = QtGui.QLabel("Serial #",self)
                  self.Input9Label.move(10,340)
                  self.Serial.move(90,340)
                  #end input 9
              
                  #start input 10
                  self.Sticker = QtGui.QLineEdit(self)
                  self.Sticker.resize(150,25)
                  self.Input10Label = QtGui.QLabel("Sticker #",self)
                  self.Input10Label.move(10,370)
                  self.Sticker.move(90,370)
                  #end input 10
              
                  #start input 11
                  self.Asset = QtGui.QLineEdit(self)
                  self.Asset.resize(150,25)
                  self.Input11Label = QtGui.QLabel("Asset #",self)
                  self.Input11Label.move(10,400)
                  self.Asset.move(90,400)
                  #end input 11
              
                  #start input 12
                  self.Warranty_Expiry = QtGui.QLineEdit(self)
                  self.Warranty_Expiry.resize(150,25)
                  self.Input12Label = QtGui.QLabel("Warranty Expiry",self)
                  self.Input12Label.move(10,430)
                  self.Warranty_Expiry.move(90,430)
                  #end input 12
              
                  #
                  self.Issued_to = QtGui.QLineEdit(self)
                  self.Issued_to.resize(150,25)
                  self.Input16Label = QtGui.QLabel("Issued to",self)
                  self.Input16Label.move(10,460)
                  self.Issued_to.move(90,460)
              
                  #
              
                  #start input 13
                  self.Site = QtGui.QLineEdit(self)
                  self.Site.resize(150,25)
                  self.Input13Label = QtGui.QLabel("Site",self)
                  self.Input13Label.move(10,490)
                  self.Site.move(90,490)
                  #end input 13
              
                  #start input 14
                  self.Department = QtGui.QLineEdit(self)
                  self.Department.resize(150,25)
                  self.Input14Label = QtGui.QLabel("Department",self)
                  self.Input14Label.move(10,520)
                  self.Department.move(90,520)
                  #end input 14
              
                  #start input 15
                  self.Amount = QtGui.QLineEdit(self)
                  self.Amount.resize(150,25)
                  self.Input15Label = QLabel("Amount",self)
                  self.Input15Label.move(10,550)
                  self.Amount.move(90,550)
                  #end input 15
              
                  #Input submit
                  self.Submitbtn = QtGui.QPushButton("SUBMIT",self)
                  self.Submitbtn.clicked.connect(self.inputFunction)
                  self.Submitbtn.resize(self.Submitbtn.minimumSizeHint())
                  self.Submitbtn.move(160,580)
                  #Input end
                  self.show()
              
              def searchFunction(self):
                  SEARCH = self.search.text()
                  if SEARCH == "":
                      print "Enter something"
                  else:
                      print (SEARCH)
              
              def inputFunction(self):
                  DATE_RECEIVED    = self.Date_received.text()
                  RECEIVED_BY      = self.DATA_COMBOBOX
                  DELIVERED_BY     = self.Delivered_by.text()
                  INVOICE          = self.Invoice.text()
                  PURCHASE_ORDER   = self.Purchase_order.text()
                  MODEL            = self.Model.text()
                  SPECIFICATION    = self.Specification.text()
                  QUANTITY         = self.Quantity.text()
                  SERIAL           = self.Serial.text()
                  STICKER          = self.Sticker.text()
                  ASSET            = self.Asset.text()
                  WARRANTY_EXPIRY  = self.Warranty_Expiry.text()
                  ISSUED_TO        = self.Issued_to.text()
                  SITE             = self.Site.text()
                  DEPARTMENT       = self.Department.text()
                  AMOUNT           = self.Amount.text()
              
                  if DATE_RECEIVED == "":
                      print "full up all form"
                  else:
                      self.con = mysql.connector.connect(user="root",password="admingelo",host="localhost",database="incoming_mac")
                      self.manager = self.con.cursor()
                      self.insert_this_data = ("""INSERT INTO incoming_mac_records(DATE_RECEIVED,RECEIVED_BY,DELIVERED_BY,INVOICE_NUMBER) VALUES('%s','%s','%s',%s)"""%(DATE_RECEIVED,RECEIVED_BY,DELIVERED_BY,str(INVOICE)))
                      self.manager.execute(self.insert_this_data)
                      self.con.commit()
                      self.con.close()
                      print "Okay na bes!"
              
                      self.projectModel = QSqlQueryModel()
                      self.projectModel.setQuery("select * from incoming_mac_records",self.db)
              

              def run():
              app = QtGui.QApplication(sys.argv)
              GUI = Window()
              sys.exit(app.exec_())
              run()

              1 Reply Last reply
              0
              • the_T the_

                How do you display the data when you click the submit button?

                ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #9

                @the_ please help me

                kshegunovK 1 Reply Last reply
                0
                • the_T Offline
                  the_T Offline
                  the_
                  wrote on last edited by
                  #10

                  As far as I can see you are asking this question again and again and again. If you use the search function in this forum you could find an answer

                  here for example (you did post in there too)

                  https://forum.qt.io/topic/1168/solved-the-best-way-to-programmatically-refresh-a-qsqlquerymodel-when-the-content-of-the-query-changes/14

                  -- No support in PM --

                  ? 2 Replies Last reply
                  1
                  • ? A Former User

                    @the_ please help me

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #11

                    Please don't post the same question multiple times! It's shows disrespect to the people trying to help you on their own time. Stick to your original thread and provide more information, or ask additional related questions there.
                    Consider yourself warned.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0
                    • the_T the_

                      As far as I can see you are asking this question again and again and again. If you use the search function in this forum you could find an answer

                      here for example (you did post in there too)

                      https://forum.qt.io/topic/1168/solved-the-best-way-to-programmatically-refresh-a-qsqlquerymodel-when-the-content-of-the-query-changes/14

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #12

                      @the_ how to use this code?

                      '''
                      QString queryStr = model->query().executedQuery();
                      model->clear();
                      model->query().clear();
                      model->setQuery(queryStr);

                      with this code? because this is the way i refresh a table is this bad?

                      import sys
                      import os
                      from PyQt4.QtGui import *
                      from PyQt4.QtCore import *
                      from PyQt4.QtSql import *
                      from PyQt4 import QtGui,QtCore
                      import mysql.connector

                      class Window(QtGui.QMainWindow):
                      def init(self):
                      super(Window, self).init()
                      self.setGeometry(50,50,500,300)
                      self.setWindowTitle("Inventory and Monitoring System")
                      self.setWindowIcon(QtGui.QIcon('Pictures/delta.png'))
                      QApplication.setStyle(QStyleFactory.create('Cleanlooks'))

                          self.db = QSqlDatabase.addDatabase("QMYSQL")
                      
                          self.db.setHostName("localhost")
                          self.db.setDatabaseName("incoming_mac")
                          self.db.setUserName("root")
                          self.db.setPassword("admingelo")
                          self.db.open()
                      
                          self.Date_received = QLineEdit(self)
                          self.searchbtn = QtGui.QPushButton("SUBMIT",self)
                          self.searchbtn.clicked.connect(self.Database)
                          self.searchbtn.move(10,50)
                          self.searchbtn1 = QtGui.QPushButton("REFRESH",self)
                          self.searchbtn1.clicked.connect(self.RefreshTable)
                          self.searchbtn1.move(10,90)
                      
                          self.show()
                         
                      
                      def Database(self):
                          DATE_RECEIVED = self.Date_received.text()
                          self.con = mysql.connector.connect(user="root",password="admingelo",host="localhost",database="incoming_mac")
                          self.manager = self.con.cursor()
                          self.insert_this_data = ("""INSERT INTO incoming_mac_records(DATE_RECEIVED) VALUES('%s')"""%str(DATE_RECEIVED))
                          self.manager.execute(self.insert_this_data)
                          self.con.commit()
                          self.con.close()
                      
                      def RefreshTable(self):
                          self.projectModel = QSqlQueryModel()
                          self.projectModel.setQuery("select * from incoming_mac_records",self.db)
                      
                          self.projectView = QTableView(self)
                          self.projectView.setModel(self.projectModel)
                          self.projectView.resizeColumnsToContents()
                      
                          self.projectView.setGeometry(50,50,300,200)
                      
                       
                          self.projectView.show()
                      

                      def run():
                      app = QtGui.QApplication(sys.argv)
                      GUI = Window()
                      sys.exit(app.exec_())
                      run()

                      1 Reply Last reply
                      0
                      • the_T the_

                        As far as I can see you are asking this question again and again and again. If you use the search function in this forum you could find an answer

                        here for example (you did post in there too)

                        https://forum.qt.io/topic/1168/solved-the-best-way-to-programmatically-refresh-a-qsqlquerymodel-when-the-content-of-the-query-changes/14

                        ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by
                        #13

                        @the_ IS THIS CODE OKAY? IF I WANT TO REFRESH A TABLE EVERY 3 OR MORE SECONDS?

                        import sys
                        import time
                        import os

                        x = 0
                        while x != 3:
                        x+=1
                        print (x)
                        #
                        '''
                        AND THE FUNCTION HERE TO REFRESH EVERY 3 OR MORE SECONDS?
                        '''
                        #
                        time.sleep(2)
                        if x >= 3:
                        x = 0

                        1 Reply Last reply
                        0
                        • the_T Offline
                          the_T Offline
                          the_
                          wrote on last edited by
                          #14

                          Take a look at QTimer

                          -- No support in PM --

                          ? 1 Reply Last reply
                          0
                          • the_T the_

                            Take a look at QTimer

                            ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by A Former User
                            #15

                            @the_ how to translate this in python?

                            QString queryStr = model->query().executedQuery();
                            model->clear();
                            model->query().clear();
                            model->setQuery(queryStr);

                            and what is model?

                            the_T 1 Reply Last reply
                            0
                            • BjornWB Offline
                              BjornWB Offline
                              BjornW
                              wrote on last edited by
                              #16

                              This thread must be a joke :/

                              ? 1 Reply Last reply
                              0
                              • BjornWB BjornW

                                This thread must be a joke :/

                                ? Offline
                                ? Offline
                                A Former User
                                wrote on last edited by
                                #17

                                @BjornW for you it is. Maybe your an expert in coding that's why you are so boastful i am asking because i want to understand what i ask not to tell a joke

                                don't you worry next time i will try to ask "How to handle Overconfident people"

                                1 Reply Last reply
                                0
                                • ? A Former User

                                  @the_ how to translate this in python?

                                  QString queryStr = model->query().executedQuery();
                                  model->clear();
                                  model->query().clear();
                                  model->setQuery(queryStr);

                                  and what is model?

                                  the_T Offline
                                  the_T Offline
                                  the_
                                  wrote on last edited by
                                  #18

                                  Model is the QSqlQueryModel of your QTableView

                                  -- No support in PM --

                                  1 Reply Last reply
                                  0

                                  • Login

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