Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. External process from Qml

External process from Qml

Scheduled Pinned Locked Moved Unsolved General and Desktop
34 Posts 4 Posters 16.2k 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.
  • jsulmJ jsulm

    @Naveen_D ProcessWidget::vStartProcess is currently blocking, why? Why not just start the process, connect signals/slots and return from ProcessWidget::vStartProcess ?

    void ProcessWidget::vStartProcess()
    {
        qDebug()<<"entered the function"<<endl;
        const QString program = QStringLiteral("/home/ubuntu/Documents/Sample_Examples_Qt_Qml/VoiceRecognition/VoiceRecognition");
        myProcess = new QProcess;
        connect(myProcess,SIGNAL(readyReadStandardError()),this,SLOT(vEndProcess()));
        connect(myProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(processStandardOutput()));
        connect(myProcess,SIGNAL(finished(int)),myProcess,SLOT(deleteLater()));
        connect(this,&ProcessWidget::destroyed,myProcess,&QProcess::kill);
        myProcess->start(program);
    }
    

    processStandardOutput() will be called as soon as the process is writing something to standard output.

    Naveen_DN Offline
    Naveen_DN Offline
    Naveen_D
    wrote on last edited by
    #21

    @jsulm Yes i got that...
    i want to know how to compare string s in Qml...
    the string which i am passing through the signal...i want to compare that in qml and next give functionality for that...

    i used the following code but didn't get...

    onPlaymusicsignal: {
                        console.log("Recorded Voice :" + recordedString)
                        var receivedString = recordedString
                        console.log(receivedString)
                        if(receivedString == "GOTO MUSIC")
                        {
                            console.log("play music")
                        }
                        else
                        {
                            console.log("please try again")
                        }
                    }
    

    even though the received string is GOTO MUSIC its printing in the console as please try again.

    Naveen_D

    jsulmJ 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #22

      https://forum.qt.io/topic/10210/solved-qml-strcmp-in-qml

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • Naveen_DN Naveen_D

        @jsulm Yes i got that...
        i want to know how to compare string s in Qml...
        the string which i am passing through the signal...i want to compare that in qml and next give functionality for that...

        i used the following code but didn't get...

        onPlaymusicsignal: {
                            console.log("Recorded Voice :" + recordedString)
                            var receivedString = recordedString
                            console.log(receivedString)
                            if(receivedString == "GOTO MUSIC")
                            {
                                console.log("play music")
                            }
                            else
                            {
                                console.log("please try again")
                            }
                        }
        

        even though the received string is GOTO MUSIC its printing in the console as please try again.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #23

        @Naveen_D I'm not JavaScript expert (what QML basically is), but as far as I know you can use === instead of ==
        If there maybe a new line at the end of receivedString ?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        Naveen_DN 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Naveen_D I'm not JavaScript expert (what QML basically is), but as far as I know you can use === instead of ==
          If there maybe a new line at the end of receivedString ?

          Naveen_DN Offline
          Naveen_DN Offline
          Naveen_D
          wrote on last edited by
          #24

          @jsulm @VRonin i just tried with that... i don't know do i need to use javascript for this or wat...i simply tried once with that code...
          Is it necessary to javascript to do this...because in Qt i use to do it using == so i thought here it will be the same...

          Naveen_D

          jsulmJ 1 Reply Last reply
          0
          • Naveen_DN Naveen_D

            @jsulm @VRonin i just tried with that... i don't know do i need to use javascript for this or wat...i simply tried once with that code...
            Is it necessary to javascript to do this...because in Qt i use to do it using == so i thought here it will be the same...

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #25

            @Naveen_D QML is JavaScript.
            Did you check the link provided by @VRonin ?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            Naveen_DN 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Naveen_D QML is JavaScript.
              Did you check the link provided by @VRonin ?

              Naveen_DN Offline
              Naveen_DN Offline
              Naveen_D
              wrote on last edited by
              #26

              @jsulm ya i checked...after checking that code only i used var in the code as shown above...but i didn't get that clearly so posted this in forum.

              Naveen_D

              jsulmJ 1 Reply Last reply
              0
              • Naveen_DN Naveen_D

                @jsulm ya i checked...after checking that code only i used var in the code as shown above...but i didn't get that clearly so posted this in forum.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #27

                @Naveen_D

                if(receivedString.localeCompare("GOTO MUSIC") == 0)
                {
                    console.log("play music")
                }
                else
                {
                    console.log("please try again")
                }
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                Naveen_DN 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Naveen_D

                  if(receivedString.localeCompare("GOTO MUSIC") == 0)
                  {
                      console.log("play music")
                  }
                  else
                  {
                      console.log("please try again")
                  }
                  
                  Naveen_DN Offline
                  Naveen_DN Offline
                  Naveen_D
                  wrote on last edited by
                  #28

                  @jsulm
                  i tried with both the codes...its going to else part.

                  onPlaymusicsignal: {
                                      console.log("Recorded Voice :" + recordedString)
                                      var receivedString = recordedString
                                      console.log(receivedString)
                                      if(receivedString.localeCompare("GOTO MUSIC") == 0)
                                      {
                                          console.log("play music")
                                          musicScreen.visible= true
                                      }
                                      else
                                      {
                                          console.log("please try again")
                                      }
                  
                  onPlaymusicsignal: {
                                      console.log("Recorded Voice :" + recordedString)
                                      var receivedString = recordedString
                                      var GotoMusicString = new String("GOTO MUSIC")
                                      console.log(receivedString)
                                      if(receivedString.localeCompare(GotoMusicString) == 0)
                                      {
                                          console.log("play music")
                                          musicScreen.visible= true
                                      }
                                      else
                                      {
                                          console.log("please try again")
                                      }
                                  }
                  

                  Naveen_D

                  jsulmJ 1 Reply Last reply
                  0
                  • Naveen_DN Naveen_D

                    @jsulm
                    i tried with both the codes...its going to else part.

                    onPlaymusicsignal: {
                                        console.log("Recorded Voice :" + recordedString)
                                        var receivedString = recordedString
                                        console.log(receivedString)
                                        if(receivedString.localeCompare("GOTO MUSIC") == 0)
                                        {
                                            console.log("play music")
                                            musicScreen.visible= true
                                        }
                                        else
                                        {
                                            console.log("please try again")
                                        }
                    
                    onPlaymusicsignal: {
                                        console.log("Recorded Voice :" + recordedString)
                                        var receivedString = recordedString
                                        var GotoMusicString = new String("GOTO MUSIC")
                                        console.log(receivedString)
                                        if(receivedString.localeCompare(GotoMusicString) == 0)
                                        {
                                            console.log("play music")
                                            musicScreen.visible= true
                                        }
                                        else
                                        {
                                            console.log("please try again")
                                        }
                                    }
                    
                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #29

                    @Naveen_D Maybe receivedString contains a new line character at the end?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    Naveen_DN 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @Naveen_D Maybe receivedString contains a new line character at the end?

                      Naveen_DN Offline
                      Naveen_DN Offline
                      Naveen_D
                      wrote on last edited by
                      #30

                      @jsulm this is the output i am getting from the started process and the same output i am sending through the signal to qml

                      output>>>> "\n<<< please speak >>> \n\n \n\n"

                      output>>>> "Received Command: "GOTO MUSIC"\n"

                      Output of regular exp is: ""GOTO MUSIC""
                      signal data is >> ""GOTO MUSIC""

                      qml: Recorded Voice :"GOTO MUSIC"
                      qml: "GOTO MUSIC"
                      qml: please try again

                      Naveen_D

                      jsulmJ 2 Replies Last reply
                      0
                      • Naveen_DN Naveen_D

                        @jsulm this is the output i am getting from the started process and the same output i am sending through the signal to qml

                        output>>>> "\n<<< please speak >>> \n\n \n\n"

                        output>>>> "Received Command: "GOTO MUSIC"\n"

                        Output of regular exp is: ""GOTO MUSIC""
                        signal data is >> ""GOTO MUSIC""

                        qml: Recorded Voice :"GOTO MUSIC"
                        qml: "GOTO MUSIC"
                        qml: please try again

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #31

                        @Naveen_D It look like your string is not "GOTO MUSIC" but ""GOTO MUSIC""
                        You have " at the beginning and end of the string as part of the string.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • Naveen_DN Naveen_D

                          @jsulm this is the output i am getting from the started process and the same output i am sending through the signal to qml

                          output>>>> "\n<<< please speak >>> \n\n \n\n"

                          output>>>> "Received Command: "GOTO MUSIC"\n"

                          Output of regular exp is: ""GOTO MUSIC""
                          signal data is >> ""GOTO MUSIC""

                          qml: Recorded Voice :"GOTO MUSIC"
                          qml: "GOTO MUSIC"
                          qml: please try again

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #32

                          @Naveen_D To remove those " do:

                          var receivedString = recordedString.slice(1, -1)
                          

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          Naveen_DN 1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @Naveen_D To remove those " do:

                            var receivedString = recordedString.slice(1, -1)
                            
                            Naveen_DN Offline
                            Naveen_DN Offline
                            Naveen_D
                            wrote on last edited by
                            #33

                            @jsulm yes that " was the part of that string...i got the output thanks...
                            one more doubt...is there any other method...because i have lot of commands like GOTO MUSIC for which i need to give functionality.

                            Naveen_D

                            jsulmJ 1 Reply Last reply
                            0
                            • Naveen_DN Naveen_D

                              @jsulm yes that " was the part of that string...i got the output thanks...
                              one more doubt...is there any other method...because i have lot of commands like GOTO MUSIC for which i need to give functionality.

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #34

                              @Naveen_D The easiest way would be to fix your process so it does not put the recognized strings inside "".
                              If this is not possible then you need to change the way you're parsing the output of that process, so your regular exceptions do not match "

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              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