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. setTable line fails: QSqlTableModel: THIRD DEADLINE HAS PASSED HELPPPP!!
Forum Updated to NodeBB v4.3 + New Features

setTable line fails: QSqlTableModel: THIRD DEADLINE HAS PASSED HELPPPP!!

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 532 Views 2 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.
  • beTTyB Offline
    beTTyB Offline
    beTTy
    wrote on last edited by
    #1

    Hi All,
    I have been trying for a while to use an SQL database and display on GUI using PYQT5.
    I am trying to create an interface where users will enter an event, a date and a time. I want these to be inserted into row of MySQL table.

    I was able to establish connection to database
    db.open() shows true. but when try to create table model it crashes at line setTable(""). when I comment this line rest of code runs and empty window opens.

    PLEASE PLEASE PLEASE HELP

    see sample code below:

    def createConnection():
    db = QtSql.QSqlDatabase().addDatabase("QMYSQL")
    db.setHostName("Y3tti")
    db.setDatabaseName("banshe")
    db.setUserName("user")
    db.setPassword("password")
    print("sec conn")
    print(db.open())

    class thirdwindow(QtWidgets.QMainWindow):
    def init(self, parent=None):
    super(thirdwindow, self).init(parent)
    createConnection()
    self.initUI()

    def initUI(self):
        print('initui')
        mod = QtSql.QSqlTableModel(self)
        mod.setTable("event_record")
        print(mod.lastError().text())
        print('after set table')
        mod.setHeaderData(0, QtCore.Qt.Horizontal, "event_id")
        mod.setHeaderData(1, QtCore.Qt.Horizontal, "event_name")
        mod.setHeaderData(2, QtCore.Qt.Horizontal, "done_by")
        print('hello')
        mod.select()
        mod.rowCount()
    
        view1 = QtWidgets.QTableView(self)
        view1.setModel(mod)
        self.setCentralWidget(view1)
        self.show()
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You should add which version of Qt your are using as well as PyQt and OS.

      Also, what stack trace do you get when your application crashes ?

      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

      • Login

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