Ask / Submit

QML argument access

asked 2014-03-01 11:33:57 +0200

AL13N gravatar image

I would to have access to the process' arguments in QML.

the idea is to make a .desktop file that runs (via qmlscene or the sailfish invoker thing) a QML only app, and have it link to MIME types, so that it activates on a filetype and passes the file to it.

Application should have argv & argc, so it would be nice if ApplicationWindow QML has access to it. (perhaps via an Application QML parent object, or directly). i'm not sure, but the ApplicationWindow is Silica? is this part open-sourced too?

edit retag flag offensive close delete

2 Answers

Sort by » oldest newest most voted

answered 2014-03-01 13:05:03 +0200

Acce gravatar image

updated 2014-03-01 20:25:03 +0200

You can access the command line arguments with

Qt.application.arguments[argIndex] //access items in argv
Qt.application.arguments.length    //gives argc

in your QML. Tested and it works on Sailfish as long as you have given the args in your binary, either by

QGuiApplication app* = SailfishApp::application(argc, argv);


return SailfishApp::main(argc, argv);

Is this what you needed?

Source: apparently these properties were added in 5.1, although further documentation for the Qt -object doesn't seems to be made only for 4.x versions so far.

edit flag offensive delete publish link more


it's not perfect, but it'll do, thanks

AL13N ( 2014-03-01 14:45:22 +0200 )edit

on second thought, it's funny that the Qt global QML element is documented in 4.7 & 4.8 ... but not from 50 onwards... how odd?

funnily enough, on jolla, this works, but qt5 install on my desktop, it doesn't...? is this sailfish-specific?

AL13N ( 2014-03-01 17:38:40 +0200 )edit

answered 2014-03-01 15:14:36 +0200

AL13N gravatar image

This means that you can have a .desktop file containing

Exec=/usr/lib/qt5/bin/qmlscene %U /path/to/your/qml-app/main.qml

(in that order)

and use Qt.application.arguments[1] in your app and it triggers using the filebrowser open command.

edit flag offensive delete publish link more


Does sailfish-qml also forward CLI arguments ?

MartinK ( 2014-03-01 20:04:39 +0200 )edit

actually, this is not forwarding cli arguments, this is getting the qmlscene arguments directly, which means that the Qt.application.arguments[2] is the mail.qml file...

AL13N ( 2014-03-02 10:07:46 +0200 )edit
Login/Signup to Answer

Question tools

1 follower


Asked: 2014-03-01 11:33:57 +0200

Seen: 1,491 times

Last updated: Mar 01 '14