Questions tagged [qsqltablemodel]

A QSqlTableModel instance is used in the Qt framework to provide an editable data model for a single database table.

QSqlTableModel is a high-level interface for reading and writing database records from a single table. It is built on top of the lower-level QSqlQuery and can be used to provide data to view classes such as QTableView.

QSqlTableModel can also be used to access a database programmatically, without binding it to a view.

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

206 questions
0
votes
1 answer

How can i make a QSqlTableModel read-only?

I'm making a programm using PySide6, that will add notes from MainWindow to Journal (there is a QSqlTableModel in it), everything works fine but I cant make the table in Journal non-editable (until you click the "read-only" check-box). I've read a…
GonnaBeDev
  • 13
  • 3
0
votes
0 answers

QSqlTableModel sort by virtual column

In my SQL table a have three columns: id, Start, End Here I store dates as Unix timestamps. In my result QTableView I want to see five columns: id Start (only date) Start (only time) End (only time) Length (End - Start) For this I override: int…
MCoder
  • 126
  • 2
  • 6
0
votes
0 answers

how to use QDialog to edit data in QTableView with QSqlRelationalTableModel

I have two QTableView the first one with QSqlTableModel I have no probleme when I edit it s data using QDialog when double click event happened. self.table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows) …
0
votes
1 answer

Drop Mime data (csv file) into QTableView with custom QSqlTableModel is not working

I'm using a QTableView along with a superclassed QSqlTableModel to display a sqlite table into Qt and inserting new records dropping a csv file. I have followed the doc and came up with the example reported below. I have recreated a very light…
Buzz
  • 1,102
  • 1
  • 9
  • 24
0
votes
0 answers

How to set column index in QSqlTableModel

this time I want to change the default index of the QSqlTableModel that I have, in addition to the code, I attach an image of the result. My code is: import sys from PyQt6.QtCore import Qt, QSize from PyQt6.QtSql import QSqlTableModel,…
Raknaros
  • 45
  • 6
0
votes
0 answers

TypeError: 'PySide2.QtWidgets.QTableView.setModel' called with wrong argument types

here's my starting position: I've created an interface file using QtDesigner. In the interface file I have a model-based QTableView. I'm trying to build a model for that view, following the structure of the official PyQt documentation at…
Selim
  • 65
  • 7
0
votes
1 answer

Why does PySide6.QSql.QSqlTableModel not see one of the existing tables MS Access?

There are N tables in the DB with the following data types: Numeric, long text, date and time bigint, boolean. All of them opens, except one I'm opening a database db = QSqlDatabase("QODBC") db.setDatabaseName(r"DRIVER={Microsoft Access Driver…
XZSt4nce
  • 1
  • 1
0
votes
0 answers

How can I select a row when matching a QLineEdit string?

I´m looking for a smart way to select a specific Row without using the curser or klick inside my QSqlTableModel. Instead I would like to use a QLineEdit. So here is the function I´m using for my QLineEdit, which works well. def…
Nullschall
  • 11
  • 6
0
votes
1 answer

How to create a database table if the fields are declared at run time?

When creating table at run time using qsqlquery the fields of the sqlite database table are declared by user, and using that I want to create a table at run time. How can I do that in qsql cpp? qsqlQuery qry; qry.exec("CREATE TABLE xyz ....."); //…
yssh
  • 29
  • 5
0
votes
1 answer

QSqlTableModel.insertRecord(row, record) not inserting at specified row

Using the answer provided here, I was able to insert records into my QSqlTableModel. While this appends records to the end (row=-1) just fine, changing the row does not change where the record is inserted. How do I cause a record to be inserted at…
amateur3057
  • 345
  • 1
  • 2
  • 11
0
votes
1 answer

PyQT5, QTableView: How to check for the current row, capture "row change event"

I am working on a small proof of concept with PyQT5: A simple database query tool based on QTableView widget and SQLite database. So far, I can get basic connectivity to the database, display rows, sort by columns, etc. So far, so good! The thing…
0
votes
1 answer

PyQt5. Row editing

I made PyQt5 APP which create SQlite3 DB and show data from it in QTableView widget. I have a problem with editing rows in a widget. There are 3 buttons "Add", "Change" and "Delete" that should delete, modify and add new rows to the widget, as well…
ChainSaw
  • 29
  • 6
0
votes
0 answers

QTableView does not update after ALTER TABLE query using PySide6

I am using the QSqlTableModel and the QTableView. I want to be able to add and drop columns via the menubar in the GUI. When I trigger the SQL query, the db is altered as expected but the view won't update. I have to close and rerun the application…
Ben
  • 1
  • 2
0
votes
0 answers

Handling QSqlTableModel data on startup

I have an application of which I want data from an SQLite database to be parsed directly on startup. When starting the application, I'm calling a member function of my QSqlTableModel instance called create(): mymodel.cpp MyModel::MyModel(QObject*…
tai
  • 477
  • 1
  • 5
  • 16
0
votes
0 answers

Adding a value to a 'datetime' column caused an overflow.(Error in MS-SQL)

My code- SELECT dbo.NumericSamplesDelByTapan.TagID, dbo.Tags.TagName, dbo.Tags.Location ,(SELECT DATEADD(Millisecond, FLOOR((dbo.NumericSamplesDelByTapan.SampleDateTime - 599266080000000000) % (10000000 * 60) / 10000) , DATEADD(Minute,…