Friday, February 10, 2017

Qt Enumerations to String

Have you ever been in the need of showing a more meaningful message that just the value related to a particular Qt Enumeration? I'm talking especially about logging or debugging situations, were a sentence like "Dialog modality is Qt::WindowModal" would be far far better than "Dialog modality is 1" instead.
Although there are a lot of classes in Qt that for a particular error condition provide both the int error() and QString errorString() methods, where the former provides a numeric code related to the error (usually associated to some Enumeration) while the latest returns a human-readable description of the last error that occurred, you may experience some situations where such help is not available. So we can resort on the meta-information about Qt objects provided by the Qt framework, very well explained here.

No comments:

Post a Comment