Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Running a system command through QML - for Qt 5.4
Forum Updated to NodeBB v4.3 + New Features

Running a system command through QML - for Qt 5.4

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Charles M
    wrote on 22 Jun 2015, 06:39 last edited by Charles M
    #1

    Hi,

    Is there anyone who's figured out how to run a system command from within QML, with the current QtQuick? All the online examples I've seen are pretty old, and don't seem to reflect the current reality in Qt 5.4.2

    I've also tried to follow the online documentation, but it seems rather poor in explaining how one can connect external C++ objects into QML. From what I've seen, there are two general ways:

    1 - Define a new QML type, and somehow make it visible in main.qml. It's the somehow I haven't figured out...

    2 - add a property into some QQmlContext.

    Anybody over at Digia can give me a working example, based on your "Hello, World" QtQuick 2.0 app that QtCreator gives me? Or, at least a clear sequence of steps to follow to add in new functionality?

    Or, even better: add extra syntax that allows a user to execute a system() command from inside QML. Something like Python, Perl, and other high-level scripting languages do. No need to wrange with binding C++ classes either.

    Thanks, C

    P 1 Reply Last reply 22 Jun 2015, 07:02
    0
    • C Charles M
      22 Jun 2015, 06:39

      Hi,

      Is there anyone who's figured out how to run a system command from within QML, with the current QtQuick? All the online examples I've seen are pretty old, and don't seem to reflect the current reality in Qt 5.4.2

      I've also tried to follow the online documentation, but it seems rather poor in explaining how one can connect external C++ objects into QML. From what I've seen, there are two general ways:

      1 - Define a new QML type, and somehow make it visible in main.qml. It's the somehow I haven't figured out...

      2 - add a property into some QQmlContext.

      Anybody over at Digia can give me a working example, based on your "Hello, World" QtQuick 2.0 app that QtCreator gives me? Or, at least a clear sequence of steps to follow to add in new functionality?

      Or, even better: add extra syntax that allows a user to execute a system() command from inside QML. Something like Python, Perl, and other high-level scripting languages do. No need to wrange with binding C++ classes either.

      Thanks, C

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 22 Jun 2015, 07:02 last edited by
      #2

      Hi @Charles-M and Welcome,

      Running System Commands:
      First, to execute system commands in Qt you will need to use QProcess which is a C++ API and thus needs to be done on C++ side. Then you have to somehow utilise this C++ code (from a class ofcourse ) from QML side. You have figured out correctly the 2 ways through which it can be done.

      Define a new QML type, and somehow make it visible in main.qml. It's the somehow I haven't figured out...

      The idea here is to create a QObject-derived C++ class and expose it to QML using qmlRegisterType. After that you just need to import it on QML side and you are ready to access its functionality.
      You can find more info here.

      add a property into some QQmlContext.

      In this method too you need to create a QObject-derived C++ class and expose it to QML by setting it as property using setContextProperty.
      Then to be able to access its functions you can either

      • declare it as a public slot
      • make it Q_INVOKABLE
        More info here

      A running example using qmlRegisterType is here

      Or, even better: add extra syntax that allows a user to execute a system() command from inside QML. Something like Python, Perl, and other high-level scripting languages do. No need to wrange with binding C++ classes either.

      Since QML doesnot have access to system directly there's no way to do it purely in QML. You will have to resort to C++ classes.

      157

      1 Reply Last reply
      0

      1/2

      22 Jun 2015, 06:39

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved