How to define a term for custom taxonomy

A category is just a taxonomy. And taxonomies are made up of terms. You’ll need to set the post’s terms via wp_set_post_terms.

This should be fairly simple:

wp_set_post_terms( '42', array( 'term', 'terms', 'terms' ), 'q-categories' );