Qt-interest Archive, January 2008
Mac/Windows SQL trouble
Message 1 in thread
I have developed an application on Mac OS X 10.4/10.5 that uses the Qt
SQL classes to access a Postgresql database. I got it working
perfectly on the mac before moving to windows and building it there.
While I would expect there to be some cross-platform issues (menus,
for example), one section has me rather puzzled.
I have a QSqlRelationalTableModel that is initialized with the
following code:
serviceHistory.setEditStrategy(QSqlTableModel::OnManualSubmit);
serviceHistory.setTable("servicehistory");
serviceFilter="equipmentid="+getRecordID();
serviceHistory.setFilter(serviceFilter);
serviceHistory.setSort(serviceHistory.fieldIndex("servicedate"),
Qt::DescendingOrder);
serviceHistory
.setRelation
(serviceHistory.fieldIndex("serviceid"),QSqlRelation("serviceslist",
"id","servicedescr"));
if(!serviceHistory.select())
...
Now on the mac, this works. On Windows, however, I wind up with
problems later in my code when I actually try to use the model.
Specifically, the SQL query generated on windows (as determined by the
QSqlRelationalTableModel.query().executedQuery() function) contains a
spurious AS clause for the relational column, thus changing the column
name and breaking any subsequent code that references the column by
name. How can I fix this, or is there a better way to reference
columns? My understanding is that referencing by position is dangerous
and should be avoided, not to mention more confusing when referring to
the code later.
A little later in the code I want to map a ComboBox to the relational
column of this table model, which I have done using the following code:
int serviceIndex=serviceHistory.fieldIndex("servicedescr");
cbFilterService->setModel(serviceHistory.relationModel(serviceIndex));
Again, this works perfectly on the mac, but when I try on windows,
even after working around the first problem with the column name (by
just hard coding the field index), that second line causes the program
to crash. This is even though
serviceHistory.relationModel(serviceIndex) DOES return a valid model
pointer- I have tested it by creating a QSqlTableModel * just before
the setModel call, setting it equal to
serviceHistory.relationModel(serviceIndex) and running a number of
functions off that (such as headerData), all of which work and return
the expected results. Once I issue the setModel command, however, even
on the same pointer I just ran the other functions from, the program
crashes. Can anyone help point me in the right direction to solve
these issues? Thanks!
-----------------------------------------------
Israel Brewster
Computer Support Technician
Frontier Flying Service Inc.
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
--
[ signature omitted ]