Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Windows : QtSql.setDatabaseName not allow to connect to my SQLITE database
Qt 6.11 is out! See what's new in the release blog

Windows : QtSql.setDatabaseName not allow to connect to my SQLITE database

Scheduled Pinned Locked Moved Solved Qt for Python
qt for pythonpyside2
2 Posts 1 Posters 577 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.
  • W Offline
    W Offline
    wizard_MG
    wrote on last edited by
    #1

    Hi geeks!
    wonder why this piece of code does not work when a correct DB path is set to connect to my existing database. when no parameter is passed by it works fine but not the goal for me.

    from PySide2 import QtCore, QtWidgets, QtSql
    import os

    def createConnection(path=None):

    db = QtSql.QSqlDatabase.addDatabase("QSQLITE")
    if path is None:
    
            db.setDatabaseName(":memory:")
    else:
        if os.path.exists(path) == False:
            raise(' file to connect to db does not exist')
        else:
            db.setDatabaseName(path)
    if not db.open():
        print('Connection failed')
        return False
    else:
        return True
    

    mypath = r"Qt_Pricers/IRS/NEWirsDB.db"
    path = os.path.join(os.getcwd(), mypath)
    print(createConnection())

    1 Reply Last reply
    0
    • W Offline
      W Offline
      wizard_MG
      wrote on last edited by
      #2

      sorry miss part of my code please ignore

      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