Possible to track all triggered QActions?

  • For usage analytics I would like to track all triggered QActions globally, without resorting to implement the analytics calls in each QAction. I basically just want t track which QActions are most often used by the user.
    I know I can install an evenfilter to catch QShortcut activations (of QAction) but not if the QAction was not triggered by a shortcut.

  • Moderators

    short answer: no, there is no such builtin-functionality in Qt

  • Actually, I'm working on very much the same thing: trying to instrument our software to track usage.

    What you might try, is to use QApplication::topLevelWidgets to get pointers to your windows. Then, you use QObject::findChildren<QAction*>() on those widget to get the instantiated QActions. That only works if you give your QActions a parent, of course.

    Also, you'll need to watch out for new actions installed. You could do that by installing an eventfilter on QApplication, and looking for QChildEvents being send. If the child is a QAction, you can add it to your actions to monitor.

    You can then connect to each and every action's triggered signal. Note that in order to get useful data, you'll need to make sure you give every QAction a name as well. Otherwise, you'll have no clue which actions got triggered.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.