Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED]Function executing an action that is not there (???)

    General and Desktop
    2
    3
    1133
    Loading More Posts
    • 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.
    • I
      ivica last edited by

      Hello everyone,

      I have a rather strange problem. My application has a pushButton conected to a function. That function should fetch data from one lineEdit, query the SQLite database, and update an integer in database from 0 to 1 for name written into lineEdit. Here is the connection:

      @QtCore.QObject.connect(self.ui.buttonArchive, QtCore.SIGNAL("clicked()"), self.archive)@

      original function :

      @def archive(self):
      name = (str(self.ui.lineName.text()).upper())
      if name:
      with con:
      cur = con.cursor()
      reply = QtGui.QMessageBox.question(self, 'Archive',
      "Are you sure? ", QtGui.QMessageBox.Yes |
      QtGui.QMessageBox.No, QtGui.QMessageBox.No)
      if reply == QtGui.QMessageBox.Yes:
      cur.execute('UPDATE cases SET archived = 1 WHERE name =?',[name])@

      Problem with the above function was that it always executed the query, even thou I press NO. So I changed the code.

      This is the altered code. This one SHOULD NOT update the said integer, it should only print the name from database:

      @def archive(self):
      tempname = (str(self.ui.lineName.text()).upper())
      if temname:
      with con:
      cur = con.cursor()
      reply = QtGui.QMessageBox.question(self, 'Archive',
      "Are you sure? ", QtGui.QMessageBox.Yes |
      QtGui.QMessageBox.No, QtGui.QMessageBox.No)
      if reply == QtGui.QMessageBox.Yes:
      cur.execute('SELECT name FROM cases WHERE name = ?',[tempname])
      ime = cur.fetchone()
      print(ime)@

      however...IT STILL UPDATES the integer in the database. It prints the name if I click YES, and updates the integer no matter what I press. I have removed all from pycache dir, moved the code to another dir, changed the names of functions, modules...and it always misbehaves.

      1 Reply Last reply Reply Quote 0
      • F
        franku last edited by

        -I do not know much about pyhton, maybe the python interpreter did not translate the code again?-
        sorry did not read everyting :-)

        This, Jen, is the internet.

        1 Reply Last reply Reply Quote 0
        • I
          ivica last edited by

          I'm pretty embarrassed by this but I made 2 functions with the same code and the same name, so they both were connected to the pushbutton.

          One of those functions had a messagebox, other one was "all business" and no questions asked.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post