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 6.2k 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_

    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