Forums

OverviewV-Play 2 Support (Qt 5) › serving QML over network

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #14491

    Bas

    hi,

    i just wanted to hear your opinion about serving QML Apps over the network?

    here is a url about it:

    http://www.slideshare.net/jeremylaine/serving-qml-applications-over-the-network

    I made a sample app which can do this, but it needs a QML starting point as of the v-play engine does not understand:

    vplay.setMainQmlFileName(QUrl(“http://domain.net/qmltest/Main.qml”));

    so i would like to hear from v-play about this aproach.

     

    thanx in advance, bas

    #14492

    Alex
    V-Play Team

    Hi Bas,

    while this might not work with setting the root component to a remote one at the moment, you can use a Loader to load your qml files remotely.

    E.g. you can try this code in your Main.qml:

    import VPlay 2.0
    import QtQuick 2.0
    
    GameWindow {
      id: gameWindow
      screenWidth: 960
      screenHeight: 640
    
      Loader {
        source: "http://v-play.net/support/MainContent.qml"
      }
    }
    

    The MainContent.qml file has the following content and is on our servers:

    import VPlay 2.0
    import QtQuick 2.0
    
    Scene {
      id: scene
      width: 480
      height: 320
    
      Rectangle {
        id: rectangle
        anchors.fill: parent
        color: "grey"
    
        Image {
          source: "vplay-logo.png" // this url is relative to the qml document's url, so it's taken from our server as well
          anchors.horizontalCenter: parent.horizontalCenter
          anchors.top: parent.top
          width: parent.width
          height: 100
          fillMode: Image.PreserveAspectFit
        }
    
        Text {
          id: textElement
          text: "Hello Remote V-Play World"
          color: "#ffffff"
          anchors.centerIn: parent
        }
      }
    }
    

    Is this sufficient for your use-case?

    Cheers,
    Alex

    #14493

    Bas

    hi Alex,

     

    thanx for the fast reply, as always :)

    yes this is what i had done in a working example, and works good.

    then i have put in a factory for network access management.

    engine.setNetworkAccessManagerFactory( new MyFactory());

    #ifndef MYFACTORY_H
    #define MYFACTORY_H
    
    #include <QObject>
    #include <QQmlNetworkAccessManagerFactory>
    #include <QNetworkAccessManager>
    #include <QNetworkDiskCache>
    
    class MyFactory : public QQmlNetworkAccessManagerFactory
    {
    public:
        QNetworkAccessManager* create(QObject *parent)
        {
            QNetworkAccessManager* manager = new QNetworkAccessManager( parent );
            QNetworkDiskCache* cache = new QNetworkDiskCache(manager);
            cache->setCacheDirectory("tmp/cache/");
            manager->setCache(cache);
            return manager;
        }
    
        MyFactory();
    };
    
    #endif // MYFACTORY_H
    

    but his works on desktop, did not tried on mobile device. and i think i need to change the cache directory.

    gr, Bas

    #14494

    Alex
    V-Play Team
    #14495

    Bas

    ah great!

    #14496

    Bas

    is there some way to track if all loading (including gfx and other data) is done?

    #14497

    Alex
    V-Play Team
    #14498

    Alex
    V-Play Team

    Also I think that the asynchronous property of the loader defaults to true for remote urls, which means you can actually see the qml source loading item by item, so you might want to set visible of the Loader to false while the loader is not ready, and show a loading animation instead.

    #14499

    Bas

    cool that works good,

    #14500

    Bas

    is there anything that could be different when creating an app this way?

     

    #14501

    Alex
    V-Play Team

    You will see 😀 We didn’t try something like this excessively, so not too much of experience we can share there. Keep us updated on how it is going!

    Cheers,
    Alex

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

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support