Hi

I’ve just switched to Qt and have created a new widget derived from QLineEdit that I am trying to unit test. So far I’ve been able to test everything except some custom behavior on gain/lose focus. Basically the text of the control (potentially) changes when it gains/loses focus and I would like to test this behavior. I can’t find anything in QTest, the qtestlib tutorial, or searching this forum (I accept that my searching ability may be lacking but I tried most combinations of qtest, unit test, qtestlib, simulate, and focus) and am hoping someone can at least point me in the right direction or let me know if it isn't possible.

In short, I want a test that does the following:

Qt Code:
  1. //inside a test
  2. my_ctrl ctrl;
  3.  
  4. QTest::keyClicks(&ctrl, "1.23456789");
  5.  
  6. //how do I cause ctrl to think it has lost focus here?
  7.  
  8. QString desired_result = //desired result, something other than “1.23456789”
  9.  
  10. QCOMPARE(ctrl.text(), desired_result);
To copy to clipboard, switch view to plain text mode 

Thank you for your help