[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyQt] Obtaining a pointer to sqlite3 handle in PyQt5's binding of QtSqlDriver - a QVariant prob
From: J Barchan <jnbarchan () gmail ! com>
Date: 2019-10-12 11:51:03
Message-ID: CABz3M__wjDDbLQu7u=QtVhDDn9DUe9JZ_oisEvTTEoVPT5W52Q () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
@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 <r.andrej@gmail.com> wrote:
> Absolutely. Thank you!
>
> On Sat, 12 Oct 2019, 10:51 Phil Thompson, <phil@riverbankcomputing.com>
> 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 PyQt@riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
--
Kindest,
Jonathan
[Attachment #5 (text/html)]
<div dir="ltr"><div class="gmail_default" \
style="font-family:tahoma,sans-serif">@Andrej Radovic<br></div><div \
class="gmail_default" style="font-family:tahoma,sans-serif">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?</div><div class="gmail_default" \
style="font-family:tahoma,sans-serif">I thought it looked like you would need expert \
PyQt help for it.</div><div class="gmail_default" \
style="font-family:tahoma,sans-serif">As you can see, you get support straight from \
the horse's mouth here :)</div></div><br><div class="gmail_quote"><div dir="ltr" \
class="gmail_attr">On Sat, 12 Oct 2019 at 12:08, Andrej Radovic <<a \
href="mailto:r.andrej@gmail.com">r.andrej@gmail.com</a>> \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div \
dir="auto">Absolutely. Thank you!</div><br><div class="gmail_quote"><div dir="ltr" \
class="gmail_attr">On Sat, 12 Oct 2019, 10:51 Phil Thompson, <<a \
href="mailto:phil@riverbankcomputing.com" \
target="_blank">phil@riverbankcomputing.com</a>> wrote:<br></div><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex">On 11/10/2019 15:23, Andrej Radovic wrote:<br> \
> Hello everyone, it's my first post here, I'll get straight to the <br> \
> point.<br> > <br>
> I'm trying to register some functions in sqlite within my PyQt5 app. To <br>
> do<br>
> so<br>
> within Python, I'm trying to obtain the pointer (actually, `sqlite3 <br>
> **`) to<br>
> the<br>
> sqlite instance, so I could use sqlite3_create_function<br>
> (<a href="https://sqlite.org/c3ref/create_function.html" rel="noreferrer \
noreferrer" target="_blank">https://sqlite.org/c3ref/create_function.html</a>) \
through Python's<br> > `ctypes` (<a \
href="https://docs.python.org/3/library/ctypes.html" rel="noreferrer noreferrer" \
target="_blank">https://docs.python.org/3/library/ctypes.html</a>) and register <br> \
> my<br> > function.<br>
> <br>
> When doing this in Qt5 instead of Python, you just use<br>
> `QSqlDriver::handle()`<br>
> (<a href="https://doc.qt.io/qt-5/qsqldriver.html#handle" rel="noreferrer \
noreferrer" target="_blank">https://doc.qt.io/qt-5/qsqldriver.html#handle</a>), which \
returns a <br> > QVariant<br>
> containing the address. You cast the `QVariant.data()` appropriately <br>
> and off<br>
> you go. When I try to obtain the handle in Python , I get:<br>
> <br>
> db.driver().handle()<br>
> TypeError: unable to convert a C++ 'sqlite3*' instance to a \
Python<br> > object<br>
> <br>
> I found that this error is generated within the C++ part of qpycore<br>
> (qpy/QtCore/qpycore_chimera.cpp:1539).<br>
> The code shows that a QVariant containing a pointer to an unknown type<br>
> cannot<br>
> be translated to a Python object. However, I don't need a Python <br>
> object,<br>
> just a<br>
> pointer I can use with ctypes.<br>
> <br>
> Does anyone know of a way to do this? Thanks!<br>
<br>
In tonight's snapshot it will be converted to a voidptr object...<br>
<br>
<a href="https://www.riverbankcomputing.com/static/Docs/PyQt5/api/sip/sip-module.html#voidptr" \
rel="noreferrer noreferrer" \
target="_blank">https://www.riverbankcomputing.com/static/Docs/PyQt5/api/sip/sip-module.html#voidptr</a><br>
<br>
Is that enough?<br>
<br>
Phil<br>
</blockquote></div>
_______________________________________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" \
target="_blank">PyQt@riverbankcomputing.com</a><br> <a \
href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" \
target="_blank">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br> \
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" \
class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><span \
style="font-family:tahoma,sans-serif">Kindest,</span></div><div><span \
style="font-family:tahoma,sans-serif">Jonathan</span></div></div></div></div></div>
[Attachment #6 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic