The variant can hold data of different sizes. Templates are compile time so the size needs to be constant. The best you can do is assume a size of the biggest type you support. You can for example create a union of all supported types and get a sizeof of that. This is kinda what QVariant does inside so you'd be re-inventing a wheel a little, but that's one way to do it.