Ask / Submit
0

How to run a command in QML?

asked 2017-02-14 14:27:41 +0300

Alen gravatar image

As in the update 2.0.4 the codes of device lock has changed. Before the update I could use:

DeviceLockInterface {
    id: devicelock
}

deviceLock.setState(1)

To lock the device in a QML file.

But Afterwards I should import "org.nemomobile.devicelock 1.0" to use device lock. But the command "deviceLock.setState" no longer works, not even with capital D nor with importing the library as DeviceLock.

However the dbus call still works:

sh -c "dbus-send --system --type=method_call --dest=org.nemomobile.lipstick /devicelock org.nemomobile.lipstick.devicelock.setState int32:1"

So, as a workaround, I want to run the bash script in my QML file. The QProcess didn't work for me. Is it possible to make it work by importing a library? Or any other solutions?

edit retag flag offensive close delete

Comments

Perhaps you could use DBus from QML directly? https://sailfishos.org/develop/docs/nemo-qml-plugin-dbus/

tadzik ( 2017-02-14 14:35:44 +0300 )edit

It is not possible from QML directly to execute shell commands. You could use some javascript foo that allows you that but needs importing libraries which most of them you don't need actually.

leszek ( 2017-02-14 15:02:15 +0300 )edit

@AliNa: have you made a bugreport for it? it needs to be corrected...

zlutor ( 2017-02-14 19:05:48 +0300 )edit

@zlutor, no, I didn't think that it might be a bug. Where to report BTW?

Alen ( 2017-02-14 21:21:28 +0300 )edit

@zlutor why bug? bug in your application not following updated api versions.

coderus ( 2017-02-15 15:00:01 +0300 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2017-02-14 18:57:46 +0300

velox gravatar image

updated 2017-02-14 19:07:44 +0300

Even if you shouldn't want to run a command for this, here's the answer (well, a link to learn for yourself) to your question: You can have a look at https://github.com/CODeRUS/jolla-settings-tor-button/tree/master/settings (the EnableSwitch.qml and tools.js files should point you to most of what you're asking).

The better solution for your problem, as @tadzik wrode, is using DBus directly. Look at GitHub for some Examples: https://github.com/search?q=org.nemomobile.dbus+typedCall&type=Code&utf8=%E2%9C%93

edit: the first link does not use typedCall, so I've removed the sentence claiming otherwise ;)

edit flag offensive delete publish link more
Login/Signup to Answer

Question tools

Follow
1 follower

Stats

Asked: 2017-02-14 14:27:41 +0300

Seen: 595 times

Last updated: Feb 14 '17