0
Qt QML, 그들은 작동하지만 QML 참조에는 인텔리 센스가 없습니다. 인텔리 센스를 얻을 수 있습니까?Qt QML 싱글 톤 Intellisense
pragma Singleton
import QtQuick 2.0
import QtQuick.Window 2.3
Item {
property int iMode: 0
property bool bSwapLeftRight: false
하면 등록 :
가qmlRegisterSingletonType(QUrl(QLatin1String("qrc:/GlobalSettings.qml")), "ncs.global", 1, 0, "SingletonSettings");
번째 예 ;: 제가 사용하면서 QML에서 인텔리 달성
ctxt->setContextProperty("someModel", QVariant::fromValue(ownModel));
ctxt->setContextProperty("globalControl", QVariant::fromValue(globalControl.Get()));
먼저 하나, 두 번째는 싱글이고, I는 인텔리 달성하지 . 일부 C++ 정의 된 enum을 이것을 통해 QML에 노출 시키려고하지만 IntelliSense가 제공되지 않을 때 가치를 잃습니다. 가치있는 연구를 계속하고 싶습니까?
좀 더 자세한을 추가, 주요 질문은 열거의에 대해이 아니라 인텔리 (자동 완성) :
A few snippets:
main.cpp:
//Regular Pointer
SomeModel* ownModel = new SomeModel();
//Custom Singleton implementation
GlobalControlSP globalControl = GlobalControl::GetInstance();
//I did not really want this line. GlobalControl should be singleton, how would this be threated?
qmlRegisterType<GlobalControl>("ncs.global", 1, 0, "Global");
//Registering a "Pragma Singleton" file, Intellisense do not work
qmlRegisterSingletonType(QUrl(QLatin1String("qrc:/GlobalSettings.qml")), "ncs.global", 1, 0, "SingletonSettings");
QQmlApplicationEngine engine;
QQmlContext* ctxt = engine.rootContext();
//Regular context property, not singleton. Intellisense works
ctxt->setContextProperty("ownModel", QVariant::fromValue(ownModel));
//Registering the singleton as context property, Intellisense do not work
ctxt->setContextProperty("globalControl", QVariant::fromValue(globalControl.Get()));
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
globalcontrol.h:
class GlobalControl : public QObject,
{
Q_OBJECT
Q_PROPERTY(QString backcolor READ backcolor NOTIFY backcolorChanged)
....
public:
GlobalControl(QObject *parent = nullptr);
QString backcolor() const { return m_backColor; }
....
enum EnButton
{
DEVICE_START,
DEVICE_IR,
.....
};
Q_ENUM(EnButton)
public slots:
void changeMode(int mode);
void buttonPressed(int button);
some qml file:
//This implementation works:
NcsButton {
property int valuent
id:ir
text: qsTr("IR")
width: 66 * widthScaling
Layout.row: 4
Layout.column: 1
fontColor: bIr ? valueColor : textColor
onClicked: {
globalControl.buttonPressed(Global.DEVICE_IR)
//This does not work:
NcsButton {
id:ir
text: qsTr("IR")
width: 66 * widthScaling
Layout.row: 4
Layout.column: 1
fontColor: bIr ? valueColor : textColor
onClicked: {
globalControl.buttonPressed(globalControl.DEVICE_IR)
Q_ENUM 매크로를 사용하여 C++ Enums를 노출하지 않는 이유는 무엇입니까? – derM
나는 contextproperty를 통해 액세스 할 때 작동하지 않았습니다. 싱글 톤 클래스가 아닙니다. contextproperty로 등록 된 다른 클래스에서 만든 경우 열거 형 값은 QML에서 자동 제안되지만 작동하지 않습니다. qmlRegisterType ("ncs.global", 1, 0, "Global")을 추가했습니다. 그리고 그것은 작동했습니다 –
globalControl.buttonPressed (Global.RADAR_IR) 그런 다음 동일한 클래스 enum Global.RADAR_IR을 사용하여 globalControl.buttonPressed 싱글 톤 함수에 전달합니다. 나에게 깨끗해 보이지 않는다 ... –