title: Inserting data into pyqt Qtablewidget
body: <p>I am inserting mysql data into a pyqt Qtablewidget but when I pass the data to one variabel the data is printed to only one cell into the table. Any suggestions?</p>
  
  <p>My code:</p>
  
  <pre><code>import sys
  import MySQLdb as mdb
  from PyQt4.QtGui import *
  db = mdb.connect('server','user','password','db')
  
  model = db.cursor()
  model.execute("""SELECT ip
                      FROM table""")
  rows_pong = (model.fetchall())
  data = "\n".join(item[0] for item in rows_pong)
  print data
  
  lista = [data]
  listb = ['ba', 'bb', 'bc']
  mystruct = {'A':lista, 'B':listb}
  
  class MyTable(QTableWidget):
      def __init__(self, thestruct, *args): 
          QTableWidget.__init__(self, *args)
          self.data = thestruct
          self.setHorizontalHeaderLabels(['IP Address', 'Username'])
          self.setmydata()
  
      def setmydata(self):
          for n, key in enumerate(self.data):
              for m, item in enumerate(self.data[key]):
                  newitem = QTableWidgetItem(item)
                  self.setItem(m, n, newitem)
  
  def main(args):
      app = QApplication(args)
      table = MyTable(mystruct, 100, 3)
      table.show()
      sys.exit(app.exec_())
  
  if __name__=="__main__":
      main(sys.argv)
  </code></pre>
  
  <p>Sample Data (items in the variable):</p>
  
  <pre><code>10.10.0.171:139
  
  10.10.0.171:139
  
  127.0.0.1:3306
  
  127.0.0.1:20128
  
  127.0.0.1:20129
  
  127.0.0.1:20130
  
  127.0.0.1:20130
  
  127.0.0.1:20131
  
  127.0.0.1:20131
  
  127.0.0.1:61335
  
  127.0.0.1:61561
  
  127.0.0.1:61562
  
  127.0.0.1:61942
  
  127.0.0.1:61943
  
  127.0.0.1:62291
  
  127.0.0.1:62292
  
  127.0.0.1:63093
  
  127.0.0.1:63094
  </code></pre>