[PyQt] Obtaining a pointer to sqlite3 handle in PyQt5's binding of QtSqlDriver - a QVariant problem
Phil Thompson
phil at riverbankcomputing.com
Sat Oct 12 09:51:22 BST 2019
On 11/10/2019 15:23, Andrej Radovic wrote:
> 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!
In tonight's snapshot it will be converted to a voidptr object...
https://www.riverbankcomputing.com/static/Docs/PyQt5/api/sip/sip-module.html#voidptr
Is that enough?
Phil
More information about the PyQt
mailing list