Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Function executing an action that is not there (???)

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k 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.
  • I Offline
    I Offline
    ivica
    wrote on last edited by
    #1

    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
    0
    • F Offline
      F Offline
      franku
      wrote on last edited by
      #2

      -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
      0
      • I Offline
        I Offline
        ivica
        wrote on last edited by
        #3

        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
        0

        • Login

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