On 22 May 2015 at 21:56, mark diener <rpzrpz...@gmail.com> wrote:
> Hello: > > I have a test qmlRegisterSingletonType project as listed below. > > The singleton Q_INVOKABLE functions are somehow not visible or in > "scope". > > Anybody have ideas about this? > > ##### sing.h > > #include <QObject> > > #include <QtQml> > > #include <QString> > > #include <QDebug> > > > class Sing : public QObject > > { > > Q_OBJECT > > public: > > explicit Sing(QObject *gparent = 0) { Q_UNUSED(gparent) } > > ~Sing() { } > > > Q_INVOKABLE int Buttonpress(QObject* gparm) > > { > > qDebug() << "ButtonPress:" << gparm ; > > return 22 ; > > } > > > Q_INVOKABLE QString Getcolor(QObject* gparm) > > { > > qDebug() << "GetColor:" << gparm ; > > return "red" ; > > } > > > public slots: > > signals: > > > }; > > > ###### main.cpp > > #include <QApplication>#include <QQmlApplicationEngine>#include <QQmlEngine> > #include "sing.h" > static QObject *singprovider(QQmlEngine *gengine, QJSEngine *gscriptEngine){ > Q_UNUSED(gengine) Q_UNUSED(gscriptEngine) Sing* gsing = new Sing(); > return gsing;} > int main(int argc, char *argv[]){ QApplication app(argc, argv); > QQmlApplicationEngine engine; > int gres = qmlRegisterSingletonType<Sing>("Singapi", 1, 0, "Sing", > singprovider); > qDebug() << "Register Singleton:" << gres ; > engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); > return app.exec();} > > ###### main.qml > import QtQuick 2.4import QtQuick.Controls 1.3import QtQuick.Window 2.2import > QtQuick.Layouts 1.1import Singapi 1.0 as Sing > > In this case, you should use Sing.Sing to access your singleton object , or take out "as Sing" from the import statement.
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest