Hello there,
I’m fairly new to Qt and trying to experiment with QSqlRelationalTableModel and QTableView. I’m using the SQLite driver and Qt 4.8 compiled(32bit) on Win7/64bit.
I have the following questions:
1.) My QSqlRelationalTableModel class constructor look like this:
CItemListModel::CItemListModel(){
setTable("items");
QSqlRelation q = QSqlRelation("types", "id", "title_en-US");
setRelation(fieldIndex("type"), q);
select();
}
whenever i try to set my QTableViews model to this via “setModel()” my program exits with:
ASSERT: “idx >= 0 && idx < s” in file ..\..\include/QtCore/../../src/corelib/tools/qvarlengtharray.h, line 110
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
if i change “title_en-US” to a field that doesn’t contain a minus sign everything works smoothly.
Is this a bug in Qt, or did i miss something?
2.) If i call “q.isValid()” it returns true. In fact it always returns true even if i pass incorrect data (nonexistent table/columns) to the constructor of QSqlRelation’s “aTableName”, “indexCol” and/or “displayCol” parameters. Is this how it should work?
3.) References to multiple tables:
If i have for example the following tables:
CREATE TABLE `types`(
`id` INTEGER PRIMARY KEY,
`titleEN` VARCHAR(100),
`titleFR` VARCHAR(100),
...
);
CREATE TABLE `item`(
`id` INTEGER PRIMARY KEY,
...
);
CREATE TABLE `itemTypes`(
`id` INTEGER REFERENCES `item`(`id`) ON UPDATE CASCADE ON DELETE CASCADE,
`order` INTEGER(2),
`type` INTEGER REFERENCES `types`(`id`) ON UPDATE CASCADE ON DELETE CASCADE,
PRIMARY KEY(`id`, `order`)
);
I want to have multiple “types” assigned to an “item” and have a Language code selection via a QCombobox separately (outside of my QTableView) so that only one Language can be shown/edited at a time.
Is this somehow possible with QSqlRelationTableModel possible?
4.) If i use “setQuery()” instead of “setTable()” in my QSqlRelationTableModel sorting via QTableView’s horizontalHeader is not working anymore. I could use a Proxy for sorting but then i have to fetch all data into the model first before it becomes accurate. Is there a better way to do this?
My english is not the best so sorry if something is not accurate.
Thx in advance
↧