How to use QT to simulate mouse clicks?

introduction to QT, entry to windows development.

I want to use QT to achieve a function of simulating mouse clicks (Windows platform). Specifically, it goes like this: first get the handle of a specific name window, and then simulate clicking on a specific location of the window, and require that the window can not be displayed at the front of the desktop (that is, a virtual click, rather than moving the mouse pointer to that position and then clicking)

according to the content on the Internet, I wrote a simple SLOT function as follows:

void MainWindow::clickTest()
{
    HWND hwndGameWindow=::FindWindow(NULL,L"");
    gameWindow=QWidget::find((WId)hwndGameWindow);
    qDebug()<<(QString)(gameWindow->windowTitle());
    QPoint *pos=new QPoint(112,83);
    QMouseEvent *clickEvent=new QMouseEvent(QEvent::MouseButtonPress,*pos,Qt::LeftButton,Qt::LeftButton,Qt::NoModifier);
    QApplication::sendEvent(gameWindow,clickEvent);
}

when I triggered this slot function, the system reported a segment error and the program forced to exit.
I would like to ask you what the mistake is? I would appreciate it if you could give me another way to achieve the functions I have described.

Apr.29,2021

step to see if the previous step finds a null pointer or something like


QWidget::find () applies only to windows created by the current process of Qt, while FindWindow () queries top-level windows for the entire operating system.
therefore, if you pass the window ID that is not created by the current process of Qt to QWidget::find () , it will return NULL.

to send messages to the windows of other processes, the general process is as follows

  1. use FindWindow to find the top-level window of the target window
  2. under the top-level window, use FindWindowEx to find the target window
  3. construct the message to be sent
  4. use SendMessage or PostMessage to send a message to the target window
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7b97cf-1eff4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7b97cf-1eff4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?