What's the problem with the way I handle the close_requested signal to prevent the program from exiting

Godot Version

Godot Engine v4.5.1.stable.official.f62fdbde1

Question

I created a dialog scene, and set it autoload. I want this dialog to show when I click the close button of right-top corner of window. I want to implement this feature by connecting the close_requested signal with a function.

But the code I wrote was not working. when I clicked the close button, the program was quit. I didn’t wrote any code to exit in the function.

This is my script:

extends Control


@onready var dialog: ConfirmationDialog = $ConfirmationDialog


func _ready() -> void:
	dialog.confirmed.connect(_handle_confirm)
	dialog.canceled.connect(_handle_cancel)
	get_tree().root.close_requested.connect(_handle_main_window_close)


func _handle_confirm() -> void:
	get_tree().quit()


func _handle_cancel() -> void:
	dialog.hide()


func _handle_main_window_close() -> void:
	print("handle_main_close")


func show_dialog() -> void:
	dialog.show()

You must tell Godot to not automatically handle close requests

func _ready() -> void:
    get_tree().set_auto_accept_quit(false)

Thanks, this line of code is useful, but it is for the project that has already been exported.

When I was running a project in Godot and clicked the exit button in the upper right corner, the game window disappeared but the sound continued to play, as if it were running in the background.