Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › Use Felgo inside C++ backend

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #24758

    Volker

    Hi,

    Felgo 3.10 has new Feature “Access the Connection Type of Your Mobile Device”. We have currently our JNI implementation for Android doing the same and use it inside C++ backend. Since Felgo provides implementation for both Android an iOS we would switch to Felgo’s “nativeUtils” implementation. But how to use it not in QML, but in C++ backend? Felgo includes have only fegoapplication.h and felgoliveclient.h. Should I get NativeUtils Singleton from QmlEngine via singletonInstance() or is there another way to get it?

    #24761

    Günther
    Felgo Team

    Hi Volker,

    our public APIs only include the option to use the NativeUtils object from the QML context.

    It is possible to retrieve and work with the object from the context also from C++. However, as we do not provide public headers for the NativeUtils class at the moment, I suggest to rather call the features from QML with a QQmlExpression.

    To do so, you can e.g. pass your QQmlApplicationEngine from main.cpp to the respective component you want to run QML code from. You can then use this it to e.g. retrieve the connectionType from our QML API:

    QString MyCppClass::getConnectionType() {
      // requires access to root context of QQmlApplicationEngine object
      QQmlExpression *expr = new QQmlExpression(engine->rootContext(), 0, "nativeUtils.getConnectionType()");
      QString result = expr->evaluate().toString();
      delete expr;
      return result;
    }

    If your C++ class is a QML item you can also retrieve the engine from the item context like this:

    // requires e.g. object reference o QML item
    QQmlEngine *ownerEngine = QQmlEngine::contextForObject(quickItem)->engine();

    Hope this helps!

    Best,
    Günther

    #24768

    Volker

    Hi Günther,

    this way it works perfect, thanks!

    Regards

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded