Qt QML, they do work, but no intellisense in QML references. Can I achieve intellisense?
pragma Singleton
import QtQuick 2.0
import QtQuick.Window 2.3
Item {
property int iMode: 0
property bool bSwapLeftRight: false
Registering it:
qmlRegisterSingletonType(QUrl(QLatin1String("qrc:/GlobalSettings.qml")), "ncs.global", 1, 0, "SingletonSettings" );
Second example;:
ctxt->setContextProperty("someModel", QVariant::fromValue(ownModel));
ctxt->setContextProperty("globalControl", QVariant::fromValue(globalControl.Get()));
First one i achieve IntelliSense in QML whilst using, the second one is the singleton, I do not achieve IntelliSense. Planning to expose some c++ defined enums to QML through this one, but looses value when no IntelliSense is provided..
Question is basically, do Qt Quick and Creator support IntelliSense for singleton classes ? Worthwhile investigating further?
Adding some more details, main question is NOT about enum's, but IntelliSense (auto-complete):
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)
Solution or workaround:
For QML defined singleton, add to Qt compiler QML library a generated file
..\..\..\bin\qmlplugindump -relocatable ncs.global 1.0 > plugins.qmltypes
For c++ registered singleton, make a "fake" pointer of normal class type. Register. To retrieve the enum from same singleton class, create a UncreatableType:
GlobalControlSP globalControlOrig = GlobalControl::GetInstance();
GlobalControl* globalControl = globalControlOrig.Get();
ctxt->setContextProperty("globalControl", QVariant::fromValue(globalControl));
qmlRegisterUncreatableType<GlobalControl>("ncs.global", 1, 0, "Global", "Singleton");
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments