Hi, since you only query one "field" the index is 0. Thus you can simplify your code:
Qt Code:
  1. QSqlQuery q("select count(MaDaiLy) from DaiLy, Quan where DaiLy.Quan_TenQuan = Quan.TenQuan and Quan.TenQuan = '" + ui.cbTenQuan->currentText() + "'");
  2. q.next();
  3. int SoDLHienCoTrongQuan = q.value(0).toInt();
To copy to clipboard, switch view to plain text mode 
Further have a look at QSqlQuery::bindValue().