simonpena.com Una mezcla heterogénea de tecnología y desvaríos

10Oct/11Off

Mixing QML and MeeGoTouch

When trying to invoke a MeeGoTouch application's MSheet from a QML app, I was getting the following error:

There is no instance of MDeviceProfile. Please create MComponentData first.

Using MApplication instead of QApplication would solve that, but still a MApplicationWindow would be needed to make the MSheet appear.

After searching on Google for a while (see after the snippet for the sources) and talking to gri in #harmattan, I've come up with the following solution:

#include <MApplication>
#include <MApplicationWindow>
#include <MApplicationPage>
#include <QDeclarativeEngine>
#include <QGraphicsObject>
#include <QDeclarativeComponent>
#include <QDeclarativeContext>

int main(int argc, char *argv[])
{
    MApplication app(argc, argv);
    QDeclarativeEngine engine;

    // The context is unused in this example
//    QDeclarativeContext *context = engine.rootContext();

    MApplicationWindow window;
    window.showFullScreen();

    MApplicationPage page;
    page.setPannable(false);
    page.appear(MApplication::instance()->activeWindow());

    QDeclarativeComponent component(&engine, QUrl("qrc:/qml/main.qml"));
    QGraphicsObject *content = qobject_cast<QGraphicsObject*>(component.create());
    MWidget *centralWidget = new MWidget;
    content->setParentItem(centralWidget);
    page.setCentralWidget(centralWidget);

    int result = app.exec();

    delete centralWidget;

    return result;
}

From QML support in Meego touch Framework I learnt that I had to load the QML into a MeeGoTouch widget, so I followed Loading QML components from C++ to replace the loadQmlComponent non-existing method with the QDeclarativeComponent::create approach.

Also, note that I use MApplicationWindow::showFullScreen instead of MApplicationWindow::show and MWidget::setMinimumSize

Posted by Simón

Comments (2) Trackbacks (0)
  1. There’s an easier alternative if you want to show a sheet from a QML application: create an MWindow before showing the sheet.

    win = new MWindow;
    win->showFullScreen();
    sheet->appear();

    The only drawback is that if you go to the task switcher you will see the sheet separate from the main app. That you can fix with this (before showing the MWindow):

    XSetTransientForHint(QX11Info::display(), win->effectiveWinId(), qmlview->effectiveWinId());

  2. Thanks for the feedback, Berto. Besides, it looks like the recipe I wrote there has some issues when rotating, so your solution is very welcome.


Trackbacks are disabled.