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?


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.

  • It looks like Qt.application.arguments will do roughly the same thing as my --appargs approach -- you just get a string with all the arguments. I don't know whether it will filter out the qmlscene arguments or not. Since Qt5.1 hasn't made it into Ubuntu yet, I can't test. Aug 31 '13 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.