[Qt-interest] QSqlRelation and order of items in combo box

Jan janusius at gmx.net
Fri Apr 23 10:11:32 CEST 2010


What does mMdl->relationModel(master_fld1)->fieldIndex("descr") return?

Is it really the correct column nr.?

Maybe call select() on the relationModel after populating the parent Model.

As far as I remember it worked for me.

Jan

Am 23.04.2010 10:04, schrieb Harry Sfougaris:
> Thank you for that.
> I'm afraid I must be doing something wrong, as it doesn't seem to work.
>
> I tried what you suggested right after setting the relation:
> i.e.
>   mMdl->setRelation(master_fld1, QSqlRelation("detailTbl", "id", "descr"));
>    mMdl->relationModel(master_fld1)->setSort(
>
>   mMdl->relationModel(master_fld1)->fieldIndex("descr"), Qt::AscendingOrder);
>
> But this doesn't seem to make a difference...
> Thanks,
> Harry
>
> On Fri, Apr 23, 2010 at 10:50 AM, Jan<janusius at gmx.net>  wrote:
>
>> Hi
>>
>> you could use mMdl->relationModel([column])->setSort(...);
>>
>>
>> Jan
>>
>> Am 23.04.2010 09:46, schrieb Harry Sfougaris:
>>> Hi all,
>>>
>>> When using an QSqlRelation, is there a way to specify the order of the
>> items
>>> in the detail table?
>>> If I have
>>> QSqlRelationalTableModel   *mMdl = new QSqlRelationalTableModel(this);
>>> mMdl->setTable("masterTbl");
>>> mMdl->setRelation(master_fld1, QSqlRelation("detailTbl", "id", "descr"));
>>> and then
>>> ui->tblView->setItemDelegate(new QSqlRelationalDelegate(this));
>>>
>>> I get a combo box in ui->tblView (which is a QTableView) for the field
>>> master_fld1.
>>> However, I would like to change the sort order of the items, as it is
>>> currently undefined (there is no ORDER BY section in the SQL that is sent
>> to
>>> the server for detailTbl).
>>> Can I either specify somehow an ORDER BY for QSqlRelation, or change the
>>> sort order of the items in the combo box?
>>>
>>> Thank  you,
>>> Harry
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Qt-interest mailing list
>>> Qt-interest at trolltech.com
>>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>



More information about the Qt-interest-old mailing list