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
1
vote
2 answers

QSqlTableModel::removeRow() does not delete row in SQLite database

I use Windows, C++ and Qt 5.11.1. I have a simple single-table SQLite database. This table "templates" contains primary key: id INTEGER PRIMARY KEY.When I try to remove a single row in "templates" (using QSqlTableModel), m_model.removeRow(0) returns…
ilya
  • 1,103
  • 14
  • 36
1
vote
1 answer

QTableModel Align Headers

When subclassing a QSqlTableModel is it possible to right align the headers? class SclDataModel(QSqlTableModel): def __init__(self, parent=None): super(SclDataModel, self).__init__(parent) self.setTable("scldata") …
Elcid_91
  • 1,571
  • 4
  • 24
  • 50
1
vote
1 answer

How choose the right column for a comboBox

I have a DB ('texpalsac'), Qtdesigner(ventas.ui) ,a table (products): PRODUCTS COD NAME 111 bag 112 shoes 121 pants 122 t-shirts I would like that comboBox(comboArt) show the second column ('NAME') but I dont'n know how to do it. For…
1
vote
1 answer

SQL Query; Locate and Disable

I am new at SQL, including performing queries. Everyday, our organization sends a list of employees that were terminated in a listed format. We get a text file everyday with a list of employee ID's that were terminated, that we need to deactivate in…
Josh
  • 19
  • 4
1
vote
2 answers

Editable QTableView of complex SQL query

How can I make an editable QTableView displaying data from a complex SQLite query? I need to fill a QTableView with data from several SQLite tables. This needs to be editable by the user. As the queries are a bit complex (including JOINs and CASE…
CodingCat
  • 4,999
  • 10
  • 37
  • 59
1
vote
1 answer

Qt QSortfilterproxy model virtual column

A related question has been asked by ymoreau here - but there is no decisive solution. I have subclassed QSortFilterProxyModel with the purpose to display some data in the virtual column on addition to QSqlRelationalTableModel (sourceModel) whose…
Kyef
  • 69
  • 7
1
vote
0 answers

Escape user-supplied strings for QSqlTableModel.setFilter

I want to use a QSqlTableModel to give me filtered data, with the filters derived from user input. I know that I can pass a WHERE clause without the WHERE to QSqlTableModel.setFilter. That method, however, looks very permissive (eg. it can run on…
Anaphory
  • 6,045
  • 4
  • 37
  • 68
1
vote
0 answers

filter QSqlRelationalTableModel with setFilter function to show only items that contains a specific tag/tags

I have an SQLITE Database with the following tables items(item_id,item_name,....); tags(tag_id,tag_name); items_tags(item_id,tag_id); I'm using QSqlRelationalTableModel class to for the items table. this class have this function…
sadeq
  • 21
  • 1
  • 5
1
vote
1 answer

Inserting row into QSqlTableModel

When a row is going to be edited, an index is passed into the editing dialogue. The edit works fine. When I want to add a row, I don't pass an index to the dialogue constructor, so it knows that it's supposed to add a new row. Here's the code of…
mekkanizer
  • 722
  • 2
  • 9
  • 28
1
vote
2 answers

Turn database column into Python list using PySide?

Using PySide/Qt's QSqlTableModel is there a quick, elegant way to turn a database column into a Python list? In R, for example, this would be one, short line of code. Right now, I'm manually looping over rows in Python, which seems cumbersome for a…
davideps
  • 541
  • 3
  • 13
1
vote
0 answers

How to display multiline cells in QTableView with QSqlTableModel

I have a QSqlTableModel with a table from a MySQL database, which I use to populate a table view with setModel function, this works fine but I want multiline cells in all rows of one column in order to be able to display some columns info of that…
KevinR
  • 13
  • 5
1
vote
0 answers

QTableView does not show any cell data

I have been using QTableView and QSqlTableModel. When running the program, I don't see populated results on QTableView. Here's the code so far: mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include #include…
Hari Mohan
  • 53
  • 8
1
vote
1 answer

setData returns false for QAbstractProxyModel

I have subclassed QAbstractProxyModel and its source model is a subclass of QSqlTableModel. The proxy model must show just one row of the source model at a time. Here's the code: bool SensorDisplayModel::setData(const QModelIndex &index, const…
user2522981
  • 163
  • 3
  • 18
1
vote
0 answers

Adjusting QSqlTableModel for a QTreeView

I'm trying to put a MySQL table into a treeView. Each entry has three values in the database - id, text, parentId. This treeView needs to be editable so I really like the QSqlTableModel approach, as the functionality to save back to database is…
L.Corvus
  • 23
  • 4
1
vote
0 answers

Quick row search in QSqlTableModel and SQLite

I use SQLite 3.x, Qt 5.7, C++, QSqlTableModel, QTableView classes. The table sites contains unique url column. I'd like to avoid redundant selects and minimize/exclude full resets of my model in the case of small data modifications. So, I prefer…
ilya
  • 1,103
  • 14
  • 36