Unsolved How to obtain a pointer to sqlite3 handle in PyQt5's binding of QtSqlDriver
-
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 theQVariant.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 withctypes
.Does anyone know of a way to do this? Thanks!
-
@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. -
@JonB Thanks!
-
@Denni-0
I considered doing that, writing a Python-only model class using Python's nativesqlite3
library or evensqlalchemy
, 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.