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

Harry Sfougaris hsfougaris at gmail.com
Fri Apr 23 10:20:48 CEST 2010


Calling select() after the parent model select solved it.
Tracing the SQL Server activity, it looks like as soon as I set set the
relation, the select() is executed on the relation model.
This is why setting the sort doesn't work.

It just means that I end up running the same query twice.
It would be nice if there was an option to set the QSqlRelation while either
specifying an order by, or at least deferring the select()
(I'm new to Qt so maybe what I just said is stupid).

Thanks,
Harry

On Fri, Apr 23, 2010 at 11:11 AM, Jan <janusius at gmx.net> wrote:

> 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
> >>
> >
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100423/eaefb80c/attachment.html 


More information about the Qt-interest-old mailing list