[Qt-interest] Force emitting a signal in a test?

Gordon Schumacher gordon at rebit.com
Sun Nov 22 17:29:56 CET 2009


Hong Jiang wrote:
> Hi All,
>
> I'm writing some tests for my application. In the tests, I need to
> programmatically force emit some signals. For example, I'd like to
> trigger QListWidget::itemActivated from outside the widget. Is there a
> good way to do it (without changing too much non-test code)? I know
> about the functions in QTest::, but I don't want all tests to be
> driven by simulated mouse or keyboard events (and thus having the
> tests depend on the exact placement of the widgets). Sometimes it's
> much easier to just trigger the signals directly.
>   

One option would be to make your test a friend class (possibly useful
anyway...) and then just do "emit MyClass::foo()"!  I believe that's
even within the scope of not using undocumented functionality...



More information about the Qt-interest-old mailing list