[Qt-interest] Passing arguments to SLOT()

yogesh upreti yogesh.upreti at gmail.com
Mon Jul 5 14:01:25 CEST 2010


Hi Nishant,
what I normally do to achieve this, is:
1. Define the variable as a global variable, so any change to this variable
is visible everywhere.
2. call the function in SLOT() in a normal way, and call another function in
your slot where you pass this variable, I do this when there is a slot
required to pass a specific variable (like double clicking the item in
TableWidget)

Hope this helps.

-Yogi

 Date: Mon, 05 Jul 2010 12:08:57 +0200
> From: Andre Somers <andre at familiesomers.nl>
> Subject: Re: [Qt-interest] Passing arguments to SLOT()
> To: qt-interest at trolltech.com
> Message-ID: <4C31AF39.9 at familiesomers.nl>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 5-7-2010 11:54, Nishant Sharma wrote:
> > Hi,
> > I have a function in which I have a QString; say, QString abc = "QT"
> > Now, in this function, I have a connect() statement.
> > In the SLOT function, that I call, I want to pass the variable, abc.
> > How do I achieve the same?
> >
> Hi,
>
> It looks like you may be misunderstanding the function of connect.
> Connect creates a connection between a signal and a slot. Connecting
> them causes the slot to be called when the signal is emitted. Usually,
> you create such connections at the moment of initialization of a class.
> Then, when you have an actual event you want to signal (with or without
> arguments such as your "Qt" QString), you emit the signal and be assured
> the connected slot(s) will be called.
>
> So, to pass the value of abc through the signal/slot mechanism:
>
> 1) define the signal and the slot in the classes you want them in
> 2) implement the slot function to do whatever you want
> 2) connect the signal and the slot ONCE.
> 3) emit the signal with the correct argument when that is appropriate
>
> The connect statement probably has no place in the function where you
> are dealing with the value itself.
>
> Note that it could be perfectly valid in your case to just do a direct
> method call instead of using signal/slot semantics. It all depends on
> the design of your application.
>
> Andr?
>
>
>
> --
> Nokia Certified Qt Developer.
> Interested in Qt related job offers or freelance Qt consulting work.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100705/a9a47b3a/attachment.html 


More information about the Qt-interest-old mailing list