In order to link to a question you need the question ID and, ideally, its title. You just need to call the qa_q_path() function in this way:
$url = qa_q_path($questionId, $title);
This will take care of all the URL format issues you are struggling with.