The gyrosynchrotron emission from quasi-thermal electrons and applications to solar flares