[Qt-interest] Call slot with default argument

John McClurkin jwm at nei.nih.gov
Wed Aug 5 13:51:49 CEST 2009


Justus Best wrote:
> Hi folks,
> 
> After some google-research I came across an old list entry
> http://lists.trolltech.com/qt-interest/2003-06/thread00306-0.html
> from 2003.
> My question is if there is an solution for that Problem by now. I can't
> find anything like that in the docs, but maybe I'am only looking for the
> wrong terms.
> 
> To give a minimal explanation of my Problem without reading the old list
> entry; I have two actions to sort a ListWidget ascending and descending
> and I don't want to maintain two differnent slots for this. So I have a
> slot like void sortList( Qt::SortOrder order ) which calls the Lists
> sortItems function. If I now try to connect the triggert signal of my
> action with this slot it fails because of unmatching parameters. It
> would be easy to call connect with
> action1...SLOT(sortList(Qt::AscendingOrder)) and action2 with
> SLOT(sortList(Qt::DescendingOrder)). But that isn't possible so I have
> to implement either two sort slots like sortListAsc and sortListDes, or
> if the sortList slot is more complex I have to add two wrapper slots to
> which call sortList with the right parameter.
> 
> My question is if there is a better solution for Problems like that.
> 
> Greets Justus

A third suggestion is to change the parameter of your slot to type int. 
Then just have a switch block or if-else block that sorts in the desired 
order depending on the value of int.



More information about the Qt-interest-old mailing list