I would like to have a static const object with some attributes set to some variable. To do this I've thought to derive the class and set the attributes in the derived class. Now I have to share the const object with other class, but to do this I should first cast it to the base class but I get an error.
The compiler error is because the default inheritance is private (for classes and public for structs), so you get rid of it by using
class DefaultAudioFormat : public QAudioFormat
Besides that, you should also return by const reference, because now you do a copy (you create a new QAudioFormat object instead of passing the original DefaultAudioFormat object), which results in slicing (although if every attribute is actually part of QAudioFormat then it is not such a big issue, but still).
If everything is set properly, you shouldn't need to do any typecast here. Like this: