View Full Version : Newbie TableView question

9th June 2020, 21:42
I'm new to QT but have been coding since back in the Borland C days.

I have a project that needs to be cross platform so I decided to give Qt a go.
I'm using SQlite as a back end and have a database that requires a ton of joins. I have QSqlRelationalTableModel more or less figured out but I have yet to find a way to assign certain fields to certain columns... iE change the order of display... if anyone can point me in the right direction. Code snippit below:... thanks

// QSqlRelationalTableModel ////////////////////////////////////////////////////////////////////////////////////////////////
QSqlRelationalTableModel *model = new QSqlRelationalTableModel;

model->setRelation(4, QSqlRelation("tblJewelryPiece", "JewelryPieceID", "Category"));// set Relation
model->setRelation(5, QSqlRelation("tblJewelryPiece", "JewelryPieceID", "PieceName"));// set Relation

model->setHeaderData(0, Qt::Horizontal, tr("Invoice #")); // set Header Data
model->setHeaderData(2, Qt::Horizontal, tr("Date"));
model->setHeaderData(3, Qt::Horizontal, tr("Qty"));
model->setHeaderData(4, Qt::Horizontal, tr("Category"));
model->setHeaderData(6, Qt::Horizontal, tr("Jewelry Piece"));
model->setHeaderData(7, Qt::Horizontal, tr("Price"));

model->setFilter("CustomerID=" + val); // set filter to current customer

model->select(); // select