Re: Obtaining a pointer to sqlite3 handle in PyQt5's binding of QtSqlDriver - a QVariant problem

J Barchan <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <CABz3M__wjDDbLQu7u=QtVhDDn9DUe9JZ_oisEvTTEoVPT5W52Q@mail.gmail.com>
@Andrej Radovic
I believe you are the poster at Qt forum a few days ago whom I told to join
up here to pyqt mailing list and ask your question?
I thought it looked like you would need expert PyQt help for it.
As you can see, you get support straight from the horse's mouth here :)

On Sat, 12 Oct 2019 at 12:08, Andrej Radovic <[email protected]> wrote:

> Absolutely. Thank you!
>
> On Sat, 12 Oct 2019, 10:51 Phil Thompson, <[email protected]>
> wrote:
>
>> 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
>>
> _______________________________________________
> PyQt mailing list    [email protected]
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


-- 
Kindest,
Jonathan

_______________________________________________
PyQt mailing list    [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.