void MainWindow::mousePressEvent(QMouseEvent *event) { QPointF pos = event->pos(); qDebug() << "Mouse clicked at x:" << pos.x() << "y:" << pos.y(); }
int main(int argc, char *argv[]) { SDL_Init(SDL_INIT_VIDEO); SDL_Window *window = SDL_CreateWindow("Example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0); SDL_Event event; while (true) { if (SDL_PollEvent(&event)) { if (event.type == SDL_MOUSEBUTTONDOWN) { int x, y; SDL_GetMouseState(&x, &y); std::cout << "Mouse clicked at x:" << x << " y:" << y << std::endl; } } } return 0; }In this example, we are using the SDL library to create a window and capture mouse events. When the user clicks the mouse button, we use the `SDL_GetMouseState` function to retrieve the x and y coordinates of the mouse position and print them to the console.