简体   繁体   中英

How to access template value parameter from a debugging helper in Qt Creator?

I have a class, something like

class FixedPoint<int frac> {
    ...
    private:
        std::uint32_t value;
}

I want to write a debugging helper that represents a FixedPoint value as a floating-point number. I could do that if I knew the frac value. Is there a way to access it?

For now I consider parsing value.dynamicTypeName() which seems to contain the full template name including the parameters, but it feels hacky...

Answering my own question: there are methods to access value template parameters. In my case you do it like this:

def qdump__FixedPoint(d, value):
    frac = int(value.type.template_argument(0))
    d.putValue(value['value'] / float(1 << frac))

Source .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM