[PyQt] [PYQT5]display sqlite data in Qtableview Python

J Barchan jnbarchan at gmail.com
Tue Jul 24 16:38:07 BST 2018


On 24 July 2018 at 16:24, Maziar Parsijani <maziar.parsijani at gmail.com>
wrote:

> Obviously I have a problem with creation of qsqltableview not to put just
> my data base.
> Here you can see that I can read my database :
>
>> import sqlite3
>>
>> conn = sqlite3.connect(' sqlite path to file.db ')
>> conn_cursor = conn.cursor()
>> conn.text_factory = str
>> res = conn.execute("SELECT text FROM table WHERE condition='?';")
>> for text in res:
>>     print (text[0])
>>
>  I need a help to put these data which is text in qsqltable view and the
> example have just created a db with its own data that I don't understand
> anything of it.
>
> On Tue, Jul 24, 2018 at 4:10 PM, Florian Bruhin <me at the-compiler.org>
> wrote:
>
>> On Tue, Jul 24, 2018 at 01:54:13PM +0430, Maziar Parsijani wrote:
>> > PYQT5 examples for sqlite and
>> ​​
>> QSqlTableModel are not for reading sqlite
>> > database  and show them in QSqlTableModel.
>> > I want to read my database rows and columns and show them in
>> > QSqlTableModel.Are there any good examples for such thing ?
>>
>> The examples just use an in-memory database
>> ("db.setDatabaseName(':memory:')" in connection.py). If you instead pass
>> a filename to a sqlite database, it'll read that database.
>>
>> Florian
>>
>> --
>> https://www.qutebrowser.org | me at the-compiler.org (Mail/XMPP)
>>    GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
>>          I love long mails! | https://email.is-not-s.ms/
>>
>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

​To start out from: you are using a dedicated Python import sqlite3 module.​
Unless you have a good reason (lots of existing code) which makes you want
to stick with that, I would suggest instead you consider changing over to
using the Qt MySQL database drivers (includes support for SQLite) & classes.
That will allow you to use classes like
​
QSqlTableModel easily, which in turn interface with QTableView naturally,
and there are plenty of examples of that.


-- 
Kindest,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180724/006631ea/attachment.html>


More information about the PyQt mailing list