How to use the ‘Quick edit’ option only for Admin and Editor in ‘All posts’ on the Dashboard?

Use a conditional depending on capability. Admin’s and Editors can both moderate comments so we can use the moderate_comments capability. If a user cannot moderate comments, then remove the quick edit link.

Then we can filter post_row_actions to remove the quick edit link.

function remove_quick_edit(){

    function unset_quick_edit( $actions ) {
        unset( $actions['inline hide-if-no-js'] );
            return $actions;
    }

    if ( ! current_user_can( 'moderate_comments' ) ) {
        add_filter( 'post_row_actions', 'unset_quick_edit', 10, 1 );
    }

}

add_action('admin_init', 'remove_quick_edit');