[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&#39;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 &lt;<a \
href="mailto:r.andrej@gmail.com">r.andrej@gmail.com</a>&gt; \
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, &lt;<a \
href="mailto:phil@riverbankcomputing.com" \
target="_blank">phil@riverbankcomputing.com</a>&gt; 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> \
&gt; Hello everyone, it&#39;s my first post here, I&#39;ll get straight to the <br> \
&gt; point.<br> &gt; <br>
&gt; I&#39;m trying to register some functions in sqlite within my PyQt5 app. To <br>
&gt; do<br>
&gt; so<br>
&gt; within Python, I&#39;m trying to obtain the pointer (actually, `sqlite3 <br>
&gt; **`) to<br>
&gt; the<br>
&gt; sqlite instance, so I could use sqlite3_create_function<br>
&gt; (<a href="https://sqlite.org/c3ref/create_function.html" rel="noreferrer \
noreferrer" target="_blank">https://sqlite.org/c3ref/create_function.html</a>) \
through Python&#39;s<br> &gt; `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> \
&gt; my<br> &gt; function.<br>
&gt; <br>
&gt; When doing this in Qt5 instead of Python, you just use<br>
&gt; `QSqlDriver::handle()`<br>
&gt; (<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> &gt; QVariant<br>
&gt; containing the address. You cast the `QVariant.data()` appropriately <br>
&gt; and off<br>
&gt; you go. When I try to obtain the handle in Python , I get:<br>
&gt; <br>
&gt;        db.driver().handle()<br>
&gt;        TypeError: unable to convert a C++ &#39;sqlite3*&#39; instance to a \
Python<br> &gt; object<br>
&gt; <br>
&gt; I found that this error is generated within the C++ part of qpycore<br>
&gt; (qpy/QtCore/qpycore_chimera.cpp:1539).<br>
&gt; The code shows that a QVariant containing a pointer to an unknown type<br>
&gt; cannot<br>
&gt; be translated to a Python object. However, I don&#39;t need a Python <br>
&gt; object,<br>
&gt; just a<br>
&gt; pointer I can use with ctypes.<br>
&gt; <br>
&gt; Does anyone know of a way to do this? Thanks!<br>
<br>
In tonight&#39;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