[Interest] SingletonType functions not visible in QML
Dmitry Volosnykh
dmitry.volosnykh at gmail.com
Fri May 22 16:20:36 CEST 2015
Also try naming your functions with first letter lowercased.
On Fri, May 22, 2015 at 5:06 PM, Ben Lau <xbenlau at gmail.com> wrote:
>
>
> On 22 May 2015 at 21:56, mark diener <rpzrpzrpz at 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 at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150522/5a6cc918/attachment.html>
More information about the Interest
mailing list