我正在尝试使用 qobject_cast 从QObject *转换为QSlider *,但是通过调试,变量cObj
不是NULL,但是vNumSlider
是NULL。< / p>
这是.cpp
中的一些相关摘录int main(int argc, char *argv[]) {
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QQmlComponent component(&engine,QUrl(QStringLiteral(MAIN_FORM)));
QObject *obj = component.create();
QObject *cObj = obj->findChild<QObject*>("vNumSlider");
QSlider *vNumSlider = qobject_cast<QSlider*>(cObj);
delete obj;
return app.exec();
}
和.qml
Slider {
id: vNumSlider
objectName: "vNumSlider"
maximumValue: 130
x: 85
y: 12
}