Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Send event to a QWidget
Forum Updated to NodeBB v4.3 + New Features

Send event to a QWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 7 Posters 13.4k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? A Former User

    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

    J.HilkJ Online
    J.HilkJ Online
    J.Hilk
    Moderators
    wrote on last edited by
    #2

    @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.


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #3

      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.

      mrjjM 1 Reply Last reply
      0
      • M Offline
        M Offline
        mostefa
        wrote on last edited by mostefa
        #4

        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 !

        1 Reply Last reply
        2
        • ? A Former User

          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.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @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.

          1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            Hi,

            Are you trying to implement sometihng like Squish ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #7

              @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.

              M 1 Reply Last reply
              0
              • ? A Former User

                @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.

                M Offline
                M Offline
                mostefa
                wrote on last edited by
                #8

                @mostefa and @mrjj
                Yes this method works with unit test. It's could be works for me.

                I think that for unit test it is better to use mouseClick function

                http://doc.qt.io/qt-5/qtest.html#mouseClick

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #9

                  @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?)

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    You are likely going to be interested by KDAB's GammaRay.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    M 1 Reply Last reply
                    2
                    • SGaistS SGaist

                      You are likely going to be interested by KDAB's GammaRay.

                      M Offline
                      M Offline
                      mostefa
                      wrote on last edited by
                      #11

                      @SGaist said in Send event to a QWidget:

                      You are likely going to be interested by KDAB's GammaRay.

                      Thank you for sharing

                      1 Reply Last reply
                      0
                      • ? Offline
                        ? Offline
                        A Former User
                        wrote on last edited by A Former User
                        #12

                        @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.

                        A 1 Reply Last reply
                        1
                        • ? A Former User

                          @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.

                          A Offline
                          A Offline
                          AliDamirchy
                          wrote on last edited by
                          #13

                          @Robinsondesbois can you share your result? thanks

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved