[PyQt] QAction, signals, eric4, Windows and Linux...

fpp fpp.gsp at gmail.com
Mon Aug 23 20:07:26 BST 2010


Hi,

I'm currently working on a simple app, which I code on a Windows
desktop using Designer and eric4, then copy over to a Nokia N900,
which uses a specific version of Linux (Maemo5).

I spent some time today trying to understand why the menu and toolbar
were working fine on the desktop, but not on the N900 : they are shown
normally, are interactive, but don't actually do anything (ie, slots
are never called).

After ruling out the toolbar and menu themselves, I looked into
signals and slots, specifically the "dialog code" generated by eric4
from the Designer .ui file.

For QActions, eric4 offers to generate code stubs for a number of
signals, the first of which is "activated()". Checking this for an
action named "Open" creates a stub slot method, say in mainwindow.py,
named:

on_actionOpen_activated(self):

Then in the Python version of the UI file also generated by eric4
(Ui_mainwindow.py) is the magic command:

QtCore.QMetaObject.connectSlotsByName(MainWindow)

This automatically connects the "activated()" signal of the
"actionOpen" object to the slot above.

I've used this technique in several previous projects before and never
had a problem with it, at least under Windows. But under Maemo5 it
doesn't work. Not even if I explicitly connect signal and slot (it
then fires twice in Windows, logically, but still not in Maemo).

On a hunch I looked at the (Py)Qt documentation for QAction -- which
I'd never had to do before because everything was automated by
Designer/eric4.

And the strange thing is, if I read correctly, QActions have an
"activate()" method, but no "activated()" signal ?

Their only signals are: changed(), hovered(), toggled(),
triggered()... the latter being described as "emitted when an action
is activated by the user". Duh.

So I changed the slot name to on_actionOpen_triggered(), and sure
enough the code now works both under XP and Maemo...

So I've found a reason, but not really the cause, and am left with
more questions than I started with:

- is eric4 wrong about the QAction "activated()" signal ?
- if so, why does it work under Windows ?
- does it also work under "standard" desktop Linux ?
- or is it a specific Qt/PyQt bug in Maemo ?

Thanks,
fp


More information about the PyQt mailing list