Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to obtain a pointer to sqlite3 handle in PyQt5's binding of QtSqlDriver
Servers for Qt installer are currently down

How to obtain a pointer to sqlite3 handle in PyQt5's binding of QtSqlDriver

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 3 Posters 747 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andrejr
    wrote on 8 Oct 2019, 10:23 last edited by
    #1

    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 through Python's ctypes.

    When doing this in Qt5 instead of Python, you just use QSqlDriver::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. 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!

    J 1 Reply Last reply 8 Oct 2019, 11:44
    0
    • A andrejr
      8 Oct 2019, 10:23

      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 through Python's ctypes.

      When doing this in Qt5 instead of Python, you just use QSqlDriver::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. 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!

      J Offline
      J Offline
      JonB
      wrote on 8 Oct 2019, 11:44 last edited by
      #2

      @andrejr
      If you do not get an answer to this here, you should go to https://riverbankcomputing.com/mailman/listinfo/pyqt and join the PyQt mailing list for this question, where I think you will find it will be answered.

      A 1 Reply Last reply 8 Oct 2019, 12:14
      1
      • J JonB
        8 Oct 2019, 11:44

        @andrejr
        If you do not get an answer to this here, you should go to https://riverbankcomputing.com/mailman/listinfo/pyqt and join the PyQt mailing list for this question, where I think you will find it will be answered.

        A Offline
        A Offline
        andrejr
        wrote on 8 Oct 2019, 12:14 last edited by
        #3

        @JonB Thanks!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andrejr
          wrote on 8 Oct 2019, 14:35 last edited by
          #4

          @Denni-0
          I considered doing that, writing a Python-only model class using Python's native sqlite3 library or even sqlalchemy, but I'm afraid it would be considerably less performant than QSqlQueryModel and QSqlTableModel. This would also require some serious changes to my app (say, the way variables are bound to queries is Qt-specific), so I'd rather keep using the Qt models if possible.

          1 Reply Last reply
          0

          1/4

          8 Oct 2019, 10:23

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved