[Qt-interest] QMetaObject::invokeMethod()
Shabd Swarup V
shabd at cadence.com
Tue Feb 3 08:49:42 CET 2009
Slot is "trigger".
void MenuItemImpl::click(QAction* targetObject)
{
std::cout<<"Executing click on QAction\n";
//targetObject->activate(QAction::Trigger);
//targetObject->trigger();
QMetaObject::invokeMethod(targetObject, "triggered",
Qt::QueuedConnection);
std::cout<<"Action complete\n";
return;
}
Try calling this click(QAction*) method and send any QAction object to
it from any application. In my case, "Action complete" is being
displayed even before the action was executed.
Hope this helps to reproduce the problem.
Thanks,
Shabd
________________________________
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Scott Aron Bloom
Sent: Tuesday, February 03, 2009 1:08 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] QMetaObject::invokeMethod()
Please don't respond to me directly...
Triggered is a signal, what is the slot you are connected to?
I know for a fact (looking at the code) it does not spawn
another thread...
Post a small reproducible example, and Ill be able to help more.
Scott
From: Shabd Swarup V [mailto:shabd at cadence.com]
Sent: Monday, February 02, 2009 11:32 PM
To: Scott Aron Bloom
Subject: RE: [Qt-interest] QMetaObject::invokeMethod()
Thanks Scott.
I have actually tried all three types of connections, i.e.
DirectConnection (same thread), QueuedConnection(multi-threaded) and
AutoConnection (effectively does both).
If I invoke the method directly, for example
targetObject->triggered(), it never returns!
I have a feeling QAction internally spawns another thread for
its execution. Do you think that's a possible scenario? If so, is there
a way to identify the end of exection of a QAction.
Thanks,
Shabd
________________________________
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Scott Aron Bloom
Sent: Tuesday, February 03, 2009 12:53 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] QMetaObject::invokeMethod()
Then you want a normal connection. A queued connection
is for multi-threaded, so it will return immediately and the signal will
be queued in the event loop for later..
Scott
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Shabd Swarup V
Sent: Monday, February 02, 2009 11:11 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] QMetaObject::invokeMethod()
Hi,
I am trying to invoke the "triggered" signal of a
QAction using the QMetaObject::invokeMethod() call. The code snippet is
given below:
QMetaObject::invokeMethod(targetObject, "triggered",
Qt::QueuedConnection);
In case of a QueuedConnection, ideally, the signal
should be queued until the event loop is able to deliver it to the slot
but I get the return even before the action has executed.
For example, there is a QAction "Open" under a MenuBar.
When it is clicked through the QMetaObject, I get a response immediately
and then the QFileDialog opens.
In case of all other widgets, this method seems to
behave well.
I hope the problem is clear. Any ideas on how I can
achieve what I am trying. I basically need to find out when the action
is finished executing.
Thanks in advance.
Regards,
Shabd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090203/c4eeca8f/attachment.html
More information about the Qt-interest-old
mailing list