Expose the RGBPickerProvider class

After your RGBPickerProvider class is created, you need to expose it in main.cpp. This allows you to use your RGBPickerProvider class in your QML code. The first thing you need to do is make sure you have the proper include statements.

#include <bb/cascades/Application>
#include <QLocale>
#include <QTranslator>
#include "applicationui.hpp"
#include <Qt/qdeclarativedebug.h>
#include "RGBPickerProvider.h"

Next, expose your RGBPickerProvider class by adding the following line before the new ApplicationUI(&app) statement:

qmlRegisterType<RGBPickerProvider>
    ("custom.pickers", 1, 0, "RGBPickerProvider");

Your completed main.cpp file should like this:

#include <bb/cascades/Application>
#include <QLocale>
#include <QTranslator>
#include "applicationui.hpp"
#include <Qt/qdeclarativedebug.h>
#include "RGBPickerProvider.h"

using namespace bb::cascades;

Q_DECL_EXPORT int main(int argc, char **argv)
{
    // This is where the server is started etc
    Application app(argc, argv);

    // Localization support
    QTranslator translator;
    QString locale_string = QLocale().name();
    QString filename = 
        QString( "CustomPickerTutorial_%1" ).arg( locale_string );
    if (translator.load(filename, "app/native/qm")) {
        app.installTranslator( &translator );
    }

    // Expose the class to QML
	qmlRegisterType<RGBPickerProvider>
        ("custom.pickers", 1, 0, "RGBPickerProvider");

    new ApplicationUI(&app);

    // We complete the transaction started in the app constructor 
    // and start the client event loop here
    return Application::exec();

    // When loop has exited, the Application deletes the scene which 
    // deletes all its children (per Qt rules for children)
}

Last modified: 2015-03-31



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus