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. How to separate channels when using qprocess?

How to separate channels when using qprocess?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 1.3k Views 1 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.
  • B Offline
    B Offline
    Bege
    wrote on last edited by
    #1

    Hey! I mean how can I assign different signals to different buttons? I'm very very new at c++ so, here is my code:

    scriptlauncher.h

    #ifndef SCRIPTLAUNCHER_H
    #define SCRIPTLAUNCHER_H
    
    #include <QObject>
    #include <QProcess>
    
    class ScriptLauncher : public QObject
    {
    
        Q_OBJECT
    
    public:
        explicit ScriptLauncher(QObject *parent = 0);
        Q_INVOKABLE void launchScript();
    
    private:
        QProcess *m_process;
    };
    
    #endif
    
    

    main.cpp

    #include "scriptlauncher.h"
    #include <QQmlContext>
    ...
        ScriptLauncher launcher;
        QQmlApplicationEngine engine;
        QQmlContext *kotu = engine.rootContext();
        kotu->setContextProperty("sLkotu", &launcher);
        QQmlContext *orta = engine.rootContext();
        orta->setContextProperty("sLorta", &launcher);
        QQmlContext *iyi = engine.rootContext();
        iyi->setContextProperty("sLiyi", &launcher);
    ...
    

    scriptlauncher.cpp

    #include "scriptlauncher.h"
    
    ScriptLauncher::ScriptLauncher(QObject *parent) :
        QObject(parent),
        m_process(new QProcess(this))
    {
    }
    
    void ScriptLauncher::launchScript()
    {
        m_process->start("python3 screen.py");
    }
    

    main.qml

    ...
    Connections {
            target: mouseArea
            onClicked: sLiyi.launchScript()
        }
    
        Connections {
            target: mouseArea1
            onClicked: sLorta.launchScript()
        }
    
        Connections {
            target: mouseArea2
            onClicked: sLkotu.launchScript()
            }
    

    codes does work but I don't know how to separete them. Thanks in advance!

    raven-worxR 1 Reply Last reply
    0
    • B Bege

      Hey! I mean how can I assign different signals to different buttons? I'm very very new at c++ so, here is my code:

      scriptlauncher.h

      #ifndef SCRIPTLAUNCHER_H
      #define SCRIPTLAUNCHER_H
      
      #include <QObject>
      #include <QProcess>
      
      class ScriptLauncher : public QObject
      {
      
          Q_OBJECT
      
      public:
          explicit ScriptLauncher(QObject *parent = 0);
          Q_INVOKABLE void launchScript();
      
      private:
          QProcess *m_process;
      };
      
      #endif
      
      

      main.cpp

      #include "scriptlauncher.h"
      #include <QQmlContext>
      ...
          ScriptLauncher launcher;
          QQmlApplicationEngine engine;
          QQmlContext *kotu = engine.rootContext();
          kotu->setContextProperty("sLkotu", &launcher);
          QQmlContext *orta = engine.rootContext();
          orta->setContextProperty("sLorta", &launcher);
          QQmlContext *iyi = engine.rootContext();
          iyi->setContextProperty("sLiyi", &launcher);
      ...
      

      scriptlauncher.cpp

      #include "scriptlauncher.h"
      
      ScriptLauncher::ScriptLauncher(QObject *parent) :
          QObject(parent),
          m_process(new QProcess(this))
      {
      }
      
      void ScriptLauncher::launchScript()
      {
          m_process->start("python3 screen.py");
      }
      

      main.qml

      ...
      Connections {
              target: mouseArea
              onClicked: sLiyi.launchScript()
          }
      
          Connections {
              target: mouseArea1
              onClicked: sLorta.launchScript()
          }
      
          Connections {
              target: mouseArea2
              onClicked: sLkotu.launchScript()
              }
      

      codes does work but I don't know how to separete them. Thanks in advance!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @Bege
      i think you are over-complicating things here.

      Either you pass a parameter to your launchScript() method.

      Or you create different launcher instances:

      QQmlApplicationEngine engine;
      ScriptLauncher sLkotu("...");
      engine.rootContext()->setContextProperty("sLkotu", &sLkotu);
      ScriptLauncher sLorta("...");
      engine.rootContext()->setContextProperty("sLorta", &sLorta);
      ScriptLauncher sLiyi("...");
      engine.rootContext()->setContextProperty("sLiyi", &sLiyi);
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      B 1 Reply Last reply
      2
      • raven-worxR raven-worx

        @Bege
        i think you are over-complicating things here.

        Either you pass a parameter to your launchScript() method.

        Or you create different launcher instances:

        QQmlApplicationEngine engine;
        ScriptLauncher sLkotu("...");
        engine.rootContext()->setContextProperty("sLkotu", &sLkotu);
        ScriptLauncher sLorta("...");
        engine.rootContext()->setContextProperty("sLorta", &sLorta);
        ScriptLauncher sLiyi("...");
        engine.rootContext()->setContextProperty("sLiyi", &sLiyi);
        
        B Offline
        B Offline
        Bege
        wrote on last edited by
        #3

        @raven-worx hey! Thanks for the help but sadly I couldn't make different launchers work.. How can I pass parameters to launcher as different individual? or maybe you can show me the way to make that launchers work? Sorry for this kinda noobs question. And before I go here is your second; Thanks!

        raven-worxR 1 Reply Last reply
        0
        • B Bege

          @raven-worx hey! Thanks for the help but sadly I couldn't make different launchers work.. How can I pass parameters to launcher as different individual? or maybe you can show me the way to make that launchers work? Sorry for this kinda noobs question. And before I go here is your second; Thanks!

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Bege
          WHAT doesn't work?!
          How it is EXACTLY supposed to work?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          B 2 Replies Last reply
          2
          • raven-worxR raven-worx

            @Bege
            WHAT doesn't work?!
            How it is EXACTLY supposed to work?

            B Offline
            B Offline
            Bege
            wrote on last edited by
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • raven-worxR raven-worx

              @Bege
              WHAT doesn't work?!
              How it is EXACTLY supposed to work?

              B Offline
              B Offline
              Bege
              wrote on last edited by
              #6

              @raven-worx Sorry haven't look carefuly. Figured it out thanks to you..

              1 Reply Last reply
              0

              • Login

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