Ubuntu – How to use Arguments in QML without getting qmlscene arguments

application-developmentqmlubuntu-sdk

I'm trying to write a QML application to be launched by qmlscene. I want this to accept arguments, so I'm using the Arguments object. However, this gets the arguments passed to qmlscene as well as those I mean to pass to my program. More problematically, if one of the arguments is a file, qmlscene tries to process it, failing or hanging. Is there a good way around this problem?

The first thing I tried was to pass the arguments in as a specific named argument that qmlscene would ignore. The launch line looks like qmlscene -I <directory> <qml file> --appargs="$*". ($* is a bashism for all the arguments as a single string.) For a single argument, this works pretty well. But if I were to want to pass more than one argument in, I'd have to parse them myself, which sort of defeats the purpose of having an argument parser.

Looking at some sample .desktop files, I noticed they put the arguments before the qml file, so I tried a command line like qmlscene "$@" -I <directory> <qml file>. This does keep qmlscene from trying to interpret these arguments. But if I don't pass any arguments, the Arguments object will happily process the arguments meant for qmlscene. So I still have to do some processing here. I can't help but suspect I missing a better way. What is it?

Best Answer

http://qt-project.org/doc/qt-5.1/qtqml/qtqml-releasenotes.html suggests that there is a Qt.application.arguments property in Qt 5.1. I do not know whether this does what's required, though.

Related Question