Unsolved Send event to a QWidget
-
Hi,
I'm working on a test application. The aim is to simule user inputs and save it into scenario.
My question is, is it possible to send a event directly to a QWidget?For the moment I work in this way : send mouse clic at (132, 42)
And I'll prefer work like that : send mouse clic at QPushButton named "myButton"With the second way, I can run my test on a server without screen.
Best regards,
robin -
@Robinsondesbois
hi,theres nothing stopping you to call the signal yourself for example
QPushbutton *btn = new QPushButton(); ... connect(btn, &QPushButton::clicked, this, &MyClass::DoStuff); btn->clicked();
DoStuff should be called without a problem.
-
Hi,
thank you for this reply.
This is a solution but we can't interact from another application.
And the aim is to create some scenario without rebuild the project. It's for the QA team. -
Hello @Robinsondesbois
I think that you can do it with the static sendEvent method
http://doc.qt.io/qt-5/qcoreapplication.html#sendEvent
QMouseEvent event(QEvent::MouseButtonPress, pos, 0, 0, 0); QApplication::sendEvent(mainWindow, &event);
Hope this can help !
-
@Robinsondesbois
Hi
is it only mouse events you want to record ?
You can use
http://doc.qt.io/qt-5/qobject.html#findChildren
To create a list of all widgets,
Then build a target list with name, and x,y for "clicking"There is also
QWidget * QWidget::childAt ( int x, int y ) const
QLabel* label= static_cast<QLabel*>(mainWindow->childAt(x,y));Also there is event filters.
That would allow you to record an interaction but for full support
you need to be able to construct the right types for each event to play it back. -
Hi,
Are you trying to implement sometihng like Squish ?
-
@SGaist
Hi! I didn't know squish. And it's exactly that I want to do !!
I test it and it's a really cool stuff :)But the licence is very expensive for me and I don't need all features. Do you know how they made that ?
@mostefa and @mrjj
Yes this method works with unit test. It's could be works for me. -
-
@mostefa
Yes mouseClick it's a good way for unit test. But I must have the pointer to the widget. The question is : can I list widget names of my soft and they property with an other software? (by binary analyse?) -
You are likely going to be interested by KDAB's GammaRay.
-
@SGaist said in Send event to a QWidget:
You are likely going to be interested by KDAB's GammaRay.
Thank you for sharing
-
@SGaist
Really cool stuff too! I try to read the source code but it's a big code base. It's hard to find a simple sample.
I'm working on it and I'll share the result. -
@Robinsondesbois can you share your result? thanks