Qt:Q_DECLARE_METATYPE和qRegisterMetaType

Qt:Q_DECLARE_METATYPE和qRegisterMetaType
@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant.
Note that if you intend to use the type in queued signal and slot connections or in QObject's property system,
you also have to call qRegisterMetaType() since the names are resolved at runtime.
    
    class BH {
public:
    BH() {
        value = 10;
    }

    int value;
};

Q_DECLARE_METATYPE(BH)
    
BH bh;
QVariant var = QVariant::fromValue(bh);

qDebug() << var.canConvert<BH>();

BH bh2 = var.value<BH>();
qDebug() << bh2.value;
    

你可能感兴趣的:(Qt:Q_DECLARE_METATYPE和qRegisterMetaType)