[PyQt] Obtaining a pointer to sqlite3 handle in PyQt5's binding of QtSqlDriver - a QVariant problem

Andrej Radovic r.andrej at gmail.com
Fri Oct 11 15:23:22 BST 2019


Hello everyone, it's my first post here, I'll get straight to the point.

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
(https://sqlite.org/c3ref/create_function.html) through Python's
`ctypes` (https://docs.python.org/3/library/ctypes.html) and register my
function.

When doing this in Qt5 instead of Python, you just use
`QSqlDriver::handle()`
(https://doc.qt.io/qt-5/qsqldriver.html#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
(qpy/QtCore/qpycore_chimera.cpp:1539).
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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20191011/937821e1/attachment.html>


More information about the PyQt mailing list