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. How to delete selected row in QListWidget(pyqt/python) from table(sqlite3 database)??
Forum Updated to NodeBB v4.3 + New Features

How to delete selected row in QListWidget(pyqt/python) from table(sqlite3 database)??

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 3.3k 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.
  • T Offline
    T Offline
    tchaler
    wrote on last edited by tchaler
    #1

    i am not getting error but the data is not deleting in the database.
    Need help!!!!

    conn = sqlite3.connect('db_iptable')
    
    c = conn.cursor()
    
    data3 = self.w.listWidget.SelectedCurrentRow().text()
    
    data3 = str(data3)
    
    query = "DELETE FROM rules WHERE id = '%s';" % data3.strip()
    
    mydata = c.execute(query)
    
    conn.commit()
    
    conn.close
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Since you are using the SQLite API you should ask the authors of that library directly.

      Otherwise, you could consider using Qt's SQL module with a QListView and a QSqlTableModel.

      On a side note, what does data3 contain ? id usually implies that it's the primary key thus a number.

      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
      2
      • T Offline
        T Offline
        tchaler
        wrote on last edited by
        #3

        Here is my database table : ("CREATE TABLE IF NOT EXISTS rules (id INTEGER PRIMARY KEY AUTOINCREMENT, chain TEXT, iface_in TEXT, iface_out TEXT, protocol TEXT, dst_addr TEXT, dst_port INTEGER, src_addr TEXT, src_port INTEGER, algo TEXT, string_match TEXT)")
        data3 will contain all the values in the selected row which is 11. i am wrong?? i am new in programming field.thanks

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I don't know. You're the author of that application so you know the content of your database and your application internals. So is that 11 a valid value ?

          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
          • T Offline
            T Offline
            tchaler
            wrote on last edited by
            #5

            example of a row : (1, input, eth0, wlan1, tcp, 192.198.184.123, 80, 192.198.184.176, 443, bm, bad).

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Do you realise that up until now, you are just giving minor elements about your application and the only Qt related part is the data3 = self.w.listWidget.SelectedCurrentRow().text() which is working ?

              If that's a row in your listWidget, then that likely means that data3 doesn't contain 11 but something similar to (1, input, eth0, wlan1, tcp, 192.198.184.123, 80, 192.198.184.176, 443, bm, bad) hence your query failing.

              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
              • T Offline
                T Offline
                tchaler
                wrote on last edited by
                #7

                my means was 11 elements in the selected row. not 11 as a value. i want to click on the row in the qlistwidget and delete it.

                jsulmJ 1 Reply Last reply
                0
                • T tchaler

                  my means was 11 elements in the selected row. not 11 as a value. i want to click on the row in the qlistwidget and delete it.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @tchaler Sorry, but what do you mean by eleven elements in the selected row? You want to delete a row using it's primary key, right?
                  In this case your query is wrong:

                  query = "DELETE FROM rules WHERE id = '%s';" % data3.strip()
                  

                  You are passing the id a string, I think it should be

                  query = "DELETE FROM rules WHERE id = %s;" % data3.strip()
                  

                  Do you store the primary key in the list view? I mean you somehow need to get the id from selected row.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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