On Vie 01 Oct 2010 03:49:09 go canal escribió:
> Hi,
> I have one more question -
>  - SignalMapper is to re-emit th signal from the source with the additional
> parameter to identify the source
>  - but how to pass the parameter emitted from the original signal ?
> 
> for example, my source has a slot which emits a String:
> public class Source extends QWidget {
>    public Signal1<String> loaded = new Signal1<String>();
>    ....
>    private void loadedCompleted () {
>           // get some data then emit
>           this.loaded.emit (st);
>    }
>  }
QSignalMapper can send int, String or inhereted Objets or QWidgets.  You can 
create a custom class that handle the orignal emited parameter with extra 
parameter to recognice the emitter. Then you can cast the Object in the slot 
and that do the trick.
> 
> In the destination side:
> public class Destination extends QWidget {
>   private QSignalMapper mapper;
>   .......
>   public void init () {
>      // establish the link
>      sourceObject.loaded.connect(mapper, "map()");
>      mapper.setMapping(sourceObject, sourceObject);
>   }
> 
>   // slot can receive the source but no parameter for the original String
>   private void processLoaded (QObject p) {
>   }
> 
> }
> 
> 
> thanks,
> canal
> 
> 
> 
> 
> ________________________________
> From: go canal <[email protected]>
> To: [email protected]
> Sent: Thu, September 30, 2010 2:39:22 PM
> Subject: Re: [Qt-jambi-interest] to determine which button is clicked in
> the signal/slot
> 
> 
> Thank you for the quick response.Everything is ok now !
>  thanks,
> canal
> 
> 
> 
> 
> ________________________________
> From: José Arcángel Salazar Delgado <[email protected]>
> To: [email protected]
> Sent: Thu, September 30, 2010 12:47:02 PM
> Subject: Re: [Qt-jambi-interest] to determine which button is clicked in
> the signal/slot
> 
> On Mié 29 Sep 2010 23:28:53 go canal escribió:
> > Thank you.
> > Here is my code - first I create a tab with a '+' button; when click the
> > '+' button, insert a new tab which has a 'x' button for removing the tab.
> > The code works - I can capture the signal and determine which tab; but
> > strange though, I capture two signals for one click. I have no idea why:
> > 
> > public class MyTab extends QTabWidget {
> > public MyTab (QWidget parent) {
> > super (parent);
> > initialize();
> > }
> > 
> > // create the home page with the '+' button.
> > private void initialize() {
> > QWidget homePage = new QWidget();
> > this.insertTab (0, homePage, "Home");
> > QPushButton plusButton = new QPushButton("+");
> > plusButton.setMaximumWidth (30);
> > plusButton.clicked.connect (this, "addTab()");
> > this.tabBar().setTabButton (0, ButtonPosition.RightSide, plusButton);
> > 
> >  signalMapper = new QSignalMapper (this);
> > 
> > }
> > private void addTab () {
> > QWidget page = new QWidget();
> > this.insertTab(1, page, "New Page");
> > // add a 'x' button
> > QPushButton deleteButton = new QPushButton("x");
> > deleteButton.setMaximumWidth(30);
> > this.tabBar().setTabButton(1, ButtonPosition.RightSide, deleteButton);
> > 
> > deleteButton.clicked.connect(signalMapper, "map()");
> > signalMapper.setMapping(deleteButton, (QObject)page);
> 
> Here is the problem. The conecction with the signal mapper  is repeated
> multiples times. If you have two tabs, you create two connections.
> Make this connection in the initialize method.
> 
> signalMapper.mappedQObject.connect(this, "deleteTab(QObject)");
> 
> > }
> > // this is called twice, why ???
> > private void deleteTab (QObject page) {
> > if (page != null && page instanceof QWidget)  {
> > int index = this.indexOf ((QWidget)page);
> > System.out.println ("delete tab " + index);
> > }
> > }
> > 
> > 
> > }
> > 
> >  thanks,
> > 
> > canal
> > 
> > 
> > 
> > 
> > ________________________________
> > From: José Arcángel Salazar Delgado <[email protected]>
> > To: [email protected]
> > Sent: Wed, September 29, 2010 10:52:59 PM
> > Subject: Re: [Qt-jambi-interest] to determine which button is clicked in
> > the signal/slot
> > 
> > On Mié 29 Sep 2010 00:41:56 go canal escribió:
> > > Hi,
> > > a newbie question and sorry if it was asked before, I googled it but
> > > have
> > > 
> > > not find good answer:
> >  > I have a tab widget, a few tabs, each tab has a close button. When I
> > > 
> > > clicked the close button, I want to remove the tab. Question is, how do
> > > I know which button is clicked in the connection:
> > > 
> > > public class MyTab extends QTabWidget {
> > > ......
> > > 
> > > private void addTab () {
> > > QPushButton deleteButton = new QPushButton("x");
> > > deleteButton.setMaximumWidth(30);
> > > tabBar.insertTab (1, "New Page");
> > > tabBar.setTabButton(1, ButtonPosition.RightSide, deleteButton);
> > > deleteButton.clicked.connect(this, "deleteTab()");
> > > }
> > > private void deleteTab () {
> > > // how do we know which button is clicked, and which tab I should
> > > remove ? }
> > 
> > Hello.
> > 
> > You have two options. One if to use the signalSender method to obtaind
> > the object that emit the  signal that triggers the slot. Two is to use
> > the QSignalMapper class to map the all the signal y one slot.
> > 
> > > }
> > > 
> > >  thanks,
> > > 
> > > canal
> > 
> > _______________________________________________
> > Qt-jambi-interest mailing list
> > [email protected]
> > http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest
> 
> _______________________________________________
> Qt-jambi-interest mailing list
> [email protected]
> http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

Reply via email to