We consider q-matroids and their associated classical matroids derived from Gabidulin rank-metric codes. We express the generalized rank weights of a Gabidulin rank-metric code in terms of Betti numbers of the dual classical matroid associated to the q-matroid corresponding to the code. In our main result, we show how these Betti numbers and their elongations determine the generalized weight polynomials for q-matroids, in particular, for the Gabidulin rank-metric codes. In addition, we demonstrate how the weight distribution and higher weight spectra of such codes can be determined directly from the associated q-matroids by using Möbius functions of its lattice of q-flats.