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

Harry Sfougaris hsfougaris at gmail.com
Fri Apr 23 10:38:18 CEST 2010


I just tried with a view, and it doesn't work at all.
It triggers the select() on the related table, but then it doesn't perform
the select() on the master table. Very strange...

What else can I use instead of QSqlRelation? Isn't it the only way to
specify relationships?
(other that doing everything manually that is)

Thanks,
Harry

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

> You are right.
> I think you can at least save one line if you set the sort after
> populating the model because setSort should trigger a reselect.
> (Although you still have two queries).
>
> I sometimes do what Andre suggests: Using a View instead of a table.
>
> But in general the QSqlRelation thing in Qt is not very good (or, needs
> more "love"). E.g. upadting the relation table is a pain.
>
> Jan
>
>
>
> Am 23.04.2010 10:20, schrieb Harry Sfougaris:
> > 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
> >>
> >
> _______________________________________________
> 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/4a8431d1/attachment.html 


More information about the Qt-interest-old mailing list