Ask / Submit
2

QML argument access

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

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
2

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

Acce gravatar image

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

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);

or

return SailfishApp::main(argc, argv);

Is this what you needed?

Source: http://qt-project.org/doc/qt-5.1/qtqml/qtqml-releasenotes.html 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

Comments

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

AL13N ( 2014-03-01 14:45:22 +0300 )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? http://qt-project.org/search/tag/global~qt~object

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 +0300 )edit
0

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

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
MimeType=video/mp4;video/mkv
NoDisplay=true

(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

Comments

Does sailfish-qml also forward CLI arguments ?

MartinK ( 2014-03-01 20:04:39 +0300 )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 +0300 )edit
Login/Signup to Answer

Question tools

Follow
1 follower

Stats

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

Seen: 1,407 times

Last updated: Mar 01 '14