Qt Code:
  1. imageLabel = QLabel()
  2. m = self.imageLabel.pixmap()
  3. image1= QImage(m)
  4. imageLabel.setPixmap(QPixmap.fromImage(image1))
  5. imageLabel.setScaledContents(True)
  6. imageLabel.setMaximumSize(QSize(115, 112))
  7.  
  8.  
  9. #storing the image into database
  10.  
  11.  
  12.  
  13. query = QSqlQuery()
  14.  
  15.  
  16.  
  17. query.prepare("INSERT INTO registration1 ( picture) "
  18. "VALUES (?)")
  19.  
  20.  
  21. picture1 = imageLabel
  22.  
  23. query.addBindValue(picture1)
  24. query.exec_()
  25. QApplication.processEvents()
  26.  
  27. #query database
  28.  
  29. print("Calls:")
  30. query.exec_("SELECT id,picture FROM registration1 "
  31. "ORDER by picture")
  32.  
  33.  
  34. while query.next():
  35. id = int(query.value(0))
  36. Result_picture = query.value(1)
  37.  
  38. picture = query.value(4)
  39.  
  40.  
  41. print(Result_picture)
  42.  
  43.  
  44.  
  45.  
  46.  
  47. imageLabel2 = QLabel()
  48.  
  49.  
  50. imageLabel2.setPixmap(QPixmap.fromImage(Result_picture))
  51. imageLabel2.setScaledContents(True)
  52. imageLabel2.setMaximumSize(QSize(115, 112))
  53. imageLabel2.show()
  54.  
  55. QApplication.processEvents()
To copy to clipboard, switch view to plain text mode 
Hello guys, is there a better way to store and retrieve image file from database in pyqt progrmming?