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. How to obtain a pointer to sqlite3 handle in PyQt5's binding of QtSqlDriver
Forum Update on Monday, May 27th 2025

How to obtain a pointer to sqlite3 handle in PyQt5's binding of QtSqlDriver

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 3 Posters 741 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.
  • A Offline
    A Offline
    andrejr
    wrote on last edited by
    #1

    I'm trying to register some functions in sqlite within my PyQt5 app. To do so within Python, I'm trying to obtain the pointer (actually, sqlite3 **) to the sqlite instance, so I could use sqlite3_create_function through Python's ctypes.

    When doing this in Qt5 instead of Python, you just use QSqlDriver::handle(), which returns a QVariant containing the address. You cast the QVariant.data() appropriately and off you go. When I try to obtain the handle in Python , I get:

    db.driver().handle()
    TypeError: unable to convert a C++ 'sqlite3*' instance to a Python object
    

    I found that this error is generated within the C++ part of qpycore. The code shows that a QVariant containing a pointer to an unknown type cannot be translated to a Python object. However, I don't need a Python object, just a pointer I can use with ctypes.

    Does anyone know of a way to do this? Thanks!

    JonBJ 1 Reply Last reply
    0
    • A andrejr

      I'm trying to register some functions in sqlite within my PyQt5 app. To do so within Python, I'm trying to obtain the pointer (actually, sqlite3 **) to the sqlite instance, so I could use sqlite3_create_function through Python's ctypes.

      When doing this in Qt5 instead of Python, you just use QSqlDriver::handle(), which returns a QVariant containing the address. You cast the QVariant.data() appropriately and off you go. When I try to obtain the handle in Python , I get:

      db.driver().handle()
      TypeError: unable to convert a C++ 'sqlite3*' instance to a Python object
      

      I found that this error is generated within the C++ part of qpycore. The code shows that a QVariant containing a pointer to an unknown type cannot be translated to a Python object. However, I don't need a Python object, just a pointer I can use with ctypes.

      Does anyone know of a way to do this? Thanks!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @andrejr
      If you do not get an answer to this here, you should go to https://riverbankcomputing.com/mailman/listinfo/pyqt and join the PyQt mailing list for this question, where I think you will find it will be answered.

      A 1 Reply Last reply
      1
      • JonBJ JonB

        @andrejr
        If you do not get an answer to this here, you should go to https://riverbankcomputing.com/mailman/listinfo/pyqt and join the PyQt mailing list for this question, where I think you will find it will be answered.

        A Offline
        A Offline
        andrejr
        wrote on last edited by
        #3

        @JonB Thanks!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andrejr
          wrote on last edited by
          #4

          @Denni-0
          I considered doing that, writing a Python-only model class using Python's native sqlite3 library or even sqlalchemy, but I'm afraid it would be considerably less performant than QSqlQueryModel and QSqlTableModel. This would also require some serious changes to my app (say, the way variables are bound to queries is Qt-specific), so I'd rather keep using the Qt models if possible.

          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