Questions tagged [qsqltablemodel]
A QSqlTableModel instance is used in the Qt framework to provide an editable data model for a single database table.
188
questions
12votes
2answers
24kviews
Set color to a QTableView row
void MyWindow::initializeModelBySQL(QSqlQueryModel *model,QTableView *table,QString sql){
model = new QSqlQueryModel(this);
model->setQuery(sql);
}
With this method i can set a ...
12votes
1answer
7kviews
How to refresh a QSqlTableModel while preserving the selection?
I am using a QSqlTableModel and QTableView to view an SQLite database table.
I would like to have the table auto refresh every second or so (it's not going to be a very large table - a couple of ...
9votes
0answers
1kviews
Implementing setEditStrategy in editable QSqlQueryModel
This is a follow-up to this question. In there, we created an editable subclass of QSqlQueryModel, to use with complex queries.
Now I need to add a functionality like QTableModel's setEditStrategy so ...
8votes
3answers
566views
QSqlQuery::prepare + MySQL ODBC Connector
I was using Qt's MySQL driver with 32bit MinGW Qt. This was working:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setDatabaseName("MyDatabase");
//SETUP
if (db.open) {
QSqlQuery q;
...
7votes
0answers
732views
QSqlTableModel::setFilter and Sql Injection
I was wondering if there is a way to prevent SQL injection while using QSqlTableModel::setFilter and no validation for WHERE clause Condition.
I don't want to use QSqlQueryModel since I need edit ...
6votes
3answers
7kviews
When or how to use fetchMore() on QSqlTableModel with a SQLite database for rowCount() to work?
My class DataTable is derived from QAbstractTableModel. It uses a QSqlTableModel object internally to fetch data from a db table. It represents a record for every row in the db (it does more but the ...
6votes
0answers
124views
Filter options provided by QSqlRelationalDelegate/QSqlRelation acourding to some WHERE close
I have a QTableView populated by QSqlRelationalTableModel.
There is a column that references another table, so when I edit/create a row, this column's editor is QCombobox which gets its data from the ...
4votes
2answers
2kviews
How to change orientation of Qt TableView
Hi I am using a QTableView to display data from a sql table using the qsqltablemodel asfollows:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui-&...
4votes
1answer
1kviews
QSqlRelationalModel model/view update after changes
I've got a problem with updating model/view after changes.
To explain better what I mean I wrote a simple example with SQLite.
So the main.cpp file:
#include <QApplication>
#include "...
3votes
3answers
2kviews
Output top few records by date using kdb
Suppose I have a table, with date, sym, and size as columns. Dates are in ascending order and sizes are in descending order for each date. How do I abridge the table, such that each date, only top ...
3votes
1answer
676views
Disable QSql(Relational)TableModel's prefetch/caching behaviour
For some (well, performance) reason, Qt's "model" classes only fetch 256 rows from the database so if you want to append the row to the end of the recordset, you, apparently, must do something along ...
3votes
2answers
2kviews
how to set/read QSqlRelationalTableModel column properties and constraints?
Is there any way to check properties and constraints for each column in a QSqlRelationalTableModel? For example, I'd like to ask my QSqlRelationalTableModel object whether a certain column can ...
3votes
2answers
887views
QSqlRelationalTableModel - insert record greater than 256
I have a table node={id,name}, and a table segment={id,nodeFrom,nodeTo} in a SQLite db, where node.id and segment.id are AUTOINCREMENT fields.
I'm creating a QSqlTableModel for Node, as follows:
...
2votes
2answers
5kviews
How to get the value in QSqlTableModel?
My database:
My code:
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("sqlite.db");
db.open();
QSqlQuery query;
query.exec("SELECT * from Expenses");
QSqlTableModel *...
2votes
1answer
822views
CheckBox in QListView using QSqlTableModel
I am learning the PyQt5 framework and attempting to build a QListView of items with a checkbox in front of each item. Most of the examples I have read don't show how to accomplish this with the ...
2votes
5answers
4kviews
QSqlRecord sets column with default value to null in query
I have a problem with inserting new QSqlRecord to Postgresql database. Target table is defined as follows:
create table samochod(
samochod_id integer primary key default nextval('samochod_id_seq'),
...
2votes
1answer
632views
How to insert row from list into QSqlTableModel?
Below is my example code.
class UI(QMainWindow):
def __init__(self):
super(UI, self).__init__()
uic.loadUi("tableview.ui", self)
self.show()
db = ...
2votes
1answer
677views
QSqlRelationalTableModel only populates first 256 records
I have the following simple model using PyQt5, sqlite3 and python3.5.2.
class choicesModel(QDialog):
def __init__(self, parent=None):
super(choicesModel, self).__init__()
query = ...
2votes
1answer
3kviews
How to show the filtered data of QSqlTableModel in another tableView in Qt?
I have loaded a database by using QSqlTableModel, and show it in tableView1. Now, I have setup a filter for this QSqlTableModel, and want to show the filtered data in tableView2. tableView1 and ...
2votes
1answer
1kviews
QDataWidgetMapper only updates first index to QSqlRelationalTableModel
I have a problem regarding parts of the QT framework. I am using QT 5.0.2 and am developing on Windows at the moment.
In my application I have a Tableview set up with a QSqlRelationalTableModel. Next ...
2votes
1answer
79views
QSqlTableModel setFilter too many arguments
I'm trying to assign a signal to a pushbutton so that it calls a function which filters and shows specific data on tableView.
but when i click on the button it says:
Type error: setFilter(self, str) ...
2votes
1answer
650views
QSqlTableModel::setData() returns false also with Qt::EditMode
The documentation of QSqlTableModel::setData() says:
Returns false if the role is not Qt::EditRole. To set data for roles other than EditRole, either use a custom proxy model or subclass ...
2votes
1answer
1kviews
QML Combobox with QSqlModel
I'm currently facing problems with populating a QML Combobox with a QSqlTableModel.
Example Database:
Table Customer Table Project
| id | name | | id | name |...
2votes
1answer
233views
Get values in one or more joined tables using PySide
I'm trying to understand the advantage of using QSqlRelationalTableModel versus QSqlTableModel when dealing with tables linked through unique IDs. In the following example, the organization field is ...
2votes
1answer
2kviews
PYQT: QSqlTableModel. How to filter numbers instead of Text
I'm developing a GUI which allows nurses and doctors to view or patients records from a sqlite database. I have been able to design a way to filter the rows using the setFilter fuction. However, here ...
2votes
1answer
409views
PyQt - trouble with reimplementing data method of QSqlTableModel
I'm a newbie with python and mainly with pyqt. The problem is simple: I have a QTableView and I want to "simply" change the color of some rows. Reading all around I found that the simplest solution ...
2votes
1answer
3kviews
PyQt5 QSqlTableModel not updating changes to database
I have a PyQt5 Application connecting to a MySQL database. I made two views connected to the same model. The views pull in data from the database just fine. Any change I make to any field in one is ...
2votes
1answer
848views
QDataWidgetMapper and QDateEdit values
I have QSqlTableModel with some table, let's suppose that it's a
model->setTable("Person");
And also I have QDataWidgetMapper which mapps some widgets (lineedits etc.) to appropriate columns in ...
2votes
1answer
691views
Error on Submit after Inserting a Row in QSqlTableModel - No Fields to update
I have a SQLite database table with the following schema:
TABLE IenState (
Id primary key,
NetId integer,
NodeId integer,
DevType text
Qos integer
)
Using a DB ...
2votes
1answer
3kviews
QTableView formatting numbers
I have created a delegate and i'm able to align and boldface the numbers on the table. I would like to force them to have two decimal places, for example 1.2 should show as 1.20.
This is the header of ...
2votes
1answer
224views
qtableview fails to display the newly inserted row
When using QtableView + QSqlTableModel combination, QtableView fails to properly display the inserted row after insertion of a new one.
The id field is hidden. The EditStrategy is OnFieldChange. There ...
2votes
1answer
377views
Slot called twice qt
I have an editable list view inside a dock widget. I wanted to keep the track of the data before the user edits and the data after the user edits. The complete concerning code is:
void MainWindow :: ...
2votes
0answers
633views
Updating row via setRecord in QSqlTableModel
I use Qt 5.7, C++, SQLite database. I have QSqlTableModel descendant class. I update rows via setRecord(), submitAll() calls (QSqlTableModel::OnManualSubmit mode). Let's set value_1 to field_1 in a ...
2votes
0answers
729views
QSqlTableModel primary key to row
I have a QSqlTableModel and I want to insert and update records in it with a special form in a child-window. It's a design choice not to allow "inline editing" which I disabled on purpose.
When the ...
2votes
0answers
541views
Qt 5.3.1 introduced issue with QSqlTableModel and QSortFilterProxyModel
I am using QSortFilterProxyModel for a lot of data models and it worked fine. After updating from Qt5.3.0 to Qt5.3.1 this changed partly.
One of my GUI panels uses a QTreeView attached to a ...
2votes
1answer
196views
Resolving complex foreign keys in QSqlRelationalTable
I'm working with QSqlRelationalModel and I have some problem.
For example if we deal with simple tables like:
Location
+------+--------+
| id | name |
+------+--------+
Department
+------+------...
2votes
0answers
666views
Grid-like Inline editing with QTableView and QSqlTableModel
I am trying to make QTableView behave like a grid table, i.e there is always one empty row in bottom where user input new records to be inserted. Think MS Access subform, or in web dev I think we call ...
1vote
2answers
3kviews
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 ...
1vote
1answer
6kviews
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 ...
1vote
2answers
1kviews
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 ...
1vote
1answer
2kviews
Subclassing QSqlTableModel insert new value
I want to show SQL data from a local db-File in a QML-Tableview and than would like to do some edits to the sql-database.
What I managed to do after about three weeks: Showing my data in a QML-...
1vote
2answers
2kviews
QSqlTableModel and DATETIME columns
I have a QTableView displaying a table using a QSqlTableModel.
In that table, I have a DATETIME column. When I add a line and try to edit
that column, I have a simple QEdit. I would like to have a ...
1vote
2answers
709views
How to show only specific rows in QSqlTableModel using combo box text?
I'm using QSqlTableModel in Qt C++ and I would like to show only the rows that contain the text that is in the QComboBox. For example, when I click on the "John" item in the combo box, the table view ...
1vote
1answer
2kviews
How to display content of multiple QSqlTableModels in one QTableView?
I have a MySql table, let's call it x:
CREATE TABLE x (
Id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
A int unsigned NOT NULL,
B int,
FOREIGN KEY (A) REFERENCES y(Id)
);
And ...
1vote
1answer
145views
Inconsistent behavior of QSqlTableModel with OnRowSubmit
Premise: this question possibly refers to two distinct problems, but I believe they might be linked. If, after comments and further research we will find out that they are actually unrelated, I will ...
1vote
1answer
415views
How to create filter rows for Qtableview with using QSqlTableModel.?
Is it possible to create row filter for Qtableview with QSqlTableModel.
I am sing " QSqlTableModel" to show the data on Qtableview from SQLite thats working. But i am trying to filter rows. ...
1vote
1answer
173views
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)...
1vote
1answer
3kviews
How to format a column with decimal numbers in QSqlTableModel
I have got a QSqlTableModel with decimal numbers in one column. How can I format this column to have numbers with 4 decimal places (e.g.: 2,3 --> 2,3000; 4,567891 --> 4,5679). I am using pyqt5.
Edit:
...
1vote
1answer
600views
Qt QSqlDatabase and QSqlTableModel compatibility with PostgreSQL view?
I have encountered a problem using QSqlTableModel on PostgreSQL view. Let me show the relevance code here first.
a view is created with the following code running on PostgreSQL 9.2.4:
CREATE OR ...
1vote
1answer
4kviews
QSQLTableModel inheritor and QTableView
I wrote QSQLTableModel inheritor for working with qml and it's work well. I need use it with QTableView too, data shows, but I cannot modify it - when I edit everything is ok, but all changes drop ...