QT unit-testing : qtestlib Segmentation fault - c++

I'm writing a test app that would test if the displayed form is the correct form. This is after pressing a key on a menu. Here's a code block where I'm getting a segmentation fault.
std::auto_ptr<MyForm> pForm(new MyForm(3,3));
QTest::keyPress(pForm.get(), Qt::Key_0);
QWidget *pWin = QApplication::activeWindow();
QCOMPARE(pWin->windowTitle(), QString("My Second Menu"));
Questions:
Is it really possible to get the currently active window when you are just simulating key presses?
I'm getting a null pointer when using activeWindow, is there anyway you could get the handle of the window that's supposed to show on the screen upon a keypress?
Thanks...

Frank was right. The window has not been acitivated synchronously. Adding a delay which is a parameter of keyPress did resolve the problem. Thanks Frank!

Related

CWnd::SetRedraw(False) make mouse go throught window

So I have a MFC application which flick when we do some action.
So I figured I would set SetRedraw(false) and set it to true at the end of the function.
The application doesn't refresh anymore but if I click on it while SetRedraw(false), my cursor is not catched by my application, it goes throught it and set focus on the application below.
Anyone has some kind of idea how I could fix that.
I ended up using CWnd::LockWindowUpdate instead after some research.
It freezes the update but doesn't act if the window was transparent.

Going back to the main page after closing the pop up window

I am having a problem on handling the pop up windows in robot framework.
The process I want to automate is :
When the button is clicked, the popup window appears. When the link from that popup window is clicked, the popup window is closed automatically and go back to the main page.
While the popup window appears, the main page is disabled, and it can be enabled only when the link from the pop up window is clicked.
The problem I have here is that I cannot go back to the main page after clicking the link from the popup window. I got the following error.
20140604 16:04:24.160 : FAIL : NoSuchWindowException: Message: u'Unable to get browser'
I hope you guys can help me solve this problem.
Thank you!
I had the same issue and here is the method to resolve the issue
String window = driver.getWindowHandle();
Now click the button to invoke the popup and give some wait time
and then switch to ur new window with the below code
driver.switchTo().window("your new window name");
//perform your action in the new window and then
To get back control over your main page after the popup closes, use the below code
driver.switchTo().window(window);
This will help you activate the main window and continue your action there.
Let me know if this helpw
No idea in Python but in Java you can use below code after pop opened to solve your problem:
Object[] parentHandle = myDriver.getWindowHandles().toArray();
myDriver.switchTo().window((String) parentHandle[0]);
In the first line of code parentHandle is the number of current
windows in Array form. And in second line of code I am switching to
the first window, for second window you can use 1.
If still have problem or you need something else, please suggest.
I have seen this issue and found that there is a recovery period where Selenium does not work correctly for a short time after closing a window. Try using a fixed delay or poll with Wait Until Keyword Succeeds combined with a keyword from Selenium2Library.

Qt OS X hiding MainWindow freezes GUI

I've found that when pressing CMD+H on my Mac and then tabbing back into the application my GUI is frozen until i minimize and maximize the window.
Any ideas what could be causing this?
I've tried:
Removing QTimer
Removing eventFilter
I'm out of ideas on what to try here.
Edit
I tried to create a new simply application that just contained a form and a text input. I deployed it using macdeployqt and I get the exact same behavior. The GUI freezes after a hit CMD+H.

Qt creator, error message

I am a little rusty with QT but I've had to use it for projects before.
I was wondering if I could make a pop-up window, a small window with it's height/width disabled so the user can't expand it. It should also lock the screen until they press a button on this window.
I could do all of this in a separate class, but I was wondering. Are there any built-in QT classes that have a little popup like this that I could just modify? I mean making a class just for an error message seems to me a little wasteful. I'm trying to keep the project small.
But if a class is required to be made in order to accomplish this, that is fine. The only problem is I have no clue how to lock the application windows so that you have to do something one window before you can go back to the main application.
I'm not asking for someone to type out all this code for me, just give me a link or something. I've looked for it but I couldn't find it. Cheers.
QMessageBox messageBox;
messageBox.critical(0,"Error","An error has occured !");
messageBox.setFixedSize(500,200);
The above code snippet will provide the required message box.
For a simple error message, I would suggest you look into the QMessageBox (the documentation contains little example that should show you how to easily achieve what you need), which is modal too. Using a QDialog for displaying a simple error message is possible too, but maybe too much for such a simple task.
I believe what you are looking for is something along the lines of QDialog. Dialogs can be modal or nonmodal. Modal dialogue "block" interaction with the calling window until the Dialog window has been handled.
You can either subclass QDialog or check to see if one of the default dialog classes will be enough for what you need.

Qt: How do I get the currently running window?

I'm writing a test app which simulates key presses and I would like to get what window is displayed after each key presses. Here's the code block.
std::auto_ptr<MyForm> pForm(new MyForm(3,3));
QTest::keyPress(pForm.get(), Qt::Key_0);
After pressing 0 here, A window is gonna show up and I would like to check what window it is so I could QCompare/evaluate it later.
Any Ideas?
Updated:
I'm getting a segmentation fault when I use
std::auto_ptr<MyForm> pForm(new MyForm(3,3));
QTest::keyPress(pForm.get(), Qt::Key_0);
QWidget *pWin = QApplication::activeWindow();
QCOMPARE(pWin->windowTitle(), QString("My Second Menu"));
If all your windows have been created through your application, you can use the QApplication class.
By example, the activeWindow() function returns the widget that have the input focus. But there's a lot of other functions that can help you.
Hope that helps