While SDL_WINDOWEVENT_CLOSE
and SDL_QUIT
are both related to closing windows, they serve different purposes.
SDL_WINDOWEVENT_CLOSE
This event is specific to an individual SDL window. It occurs when the user attempts to close a window (e.g., by clicking the close button). The event contains the windowID
, allowing you to determine which window the action applies to.
if (event.type == SDL_WINDOWEVENT &&
event.window.event == SDL_WINDOWEVENT_CLOSE) {
std::cout << "User attempted to close window ID: "
<< event.window.windowID << '\n';
}
SDL_QUIT
This event is more general and signals the application should terminate. It typically occurs when:
if (event.type == SDL_QUIT) {
std::cout << "Application quit signal received\n";
}
SDL_WINDOWEVENT_CLOSE
is window-specific, while SDL_QUIT
affects the entire application.SDL_QUIT
.Understanding this distinction helps in multi-window applications where closing one window doesn’t necessarily mean quitting the app.
Answers to questions are automatically generated and may not have been reviewed.
Discover how to monitor and respond to window state changes in SDL applications