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. Qprocess runs correctly in debug but in release mode it doesn't run correctly

Qprocess runs correctly in debug but in release mode it doesn't run correctly

Scheduled Pinned Locked Moved Solved General and Desktop
linux chromeosqprocesswaitforfinished
11 Posts 4 Posters 1.9k Views
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi and welcome to devnet,

    First thing to do: add error checks to your code.
    You are doing the assumption that everything goes well all the time which is wrong.

    Next, split the arguments properly. Each space in your string means that it should be a separated element in the argument list as explained in QProcess's documentation.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    T 1 Reply Last reply
    1
    • SGaistS SGaist

      Hi and welcome to devnet,

      First thing to do: add error checks to your code.
      You are doing the assumption that everything goes well all the time which is wrong.

      Next, split the arguments properly. Each space in your string means that it should be a separated element in the argument list as explained in QProcess's documentation.

      T Offline
      T Offline
      TahmDev
      wrote on last edited by
      #3

      @SGaist thanks for your reply, how should I add error check?!
      I ran the code in terminal and it is fine,
      Would you please explain a little more? I can't wrap my head around the reason behind my code running fine in debug and not in release

      mrjjM 1 Reply Last reply
      0
      • T TahmDev

        @SGaist thanks for your reply, how should I add error check?!
        I ran the code in terminal and it is fine,
        Would you please explain a little more? I can't wrap my head around the reason behind my code running fine in debug and not in release

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @TahmDev
        Hi
        Hook up to the signal
        https://doc.qt.io/qt-5/qprocess.html#errorOccurred
        and see if it list something when it don't work.

        T 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #5

          Please take the time to read the class documentation:

          QProcess::errorOccurred
          QProcess::error
          etc.

          As for your code, it will run faster in release than debug mode. The way you wrote your second QProcess code is wrong. You assume that it has ended after the call to closeWriteChannel which is an error.

          You should learn how to use it in asynchronous mode.

          By the way, you are "leaking" QProcess objects there. They will only be destroyed when the parent is which means you can still fill memory with them each time you call on_button_clicked.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          T 1 Reply Last reply
          0
          • mrjjM mrjj

            @TahmDev
            Hi
            Hook up to the signal
            https://doc.qt.io/qt-5/qprocess.html#errorOccurred
            and see if it list something when it don't work.

            T Offline
            T Offline
            TahmDev
            wrote on last edited by
            #6

            @mrjj hi, thanks for your reply.
            I did it but it doesn't show any errors.

            1 Reply Last reply
            0
            • T TahmDev

              Hi guys
              It's my first time posting here, I have been looking up for an answer but couldn't find one answer that could solve my problem.
              I'm tryin to write a code to attach touch devices into serial ports and manage them.
              But when I run the inputattach in my qt in debug mode, it works properly and when I run "xinput list" it shows me the added device but in relaese mode it doesn't work : here is the part of my code:

              Void Widget::on_button_clicked()
              {
              Qstring serialLocation= "/dev/ttyS0";
              QString touchName= "elotouch";
              QProcess setSerial ; 
              QString args = Qstring("inputattach --%1 %2 --daemon --always").arg(touchName) .arg(serialLocation);
              setSerial.start("/bin/bash", QStringList()<< ("-c") << args << "\n");
              setSerial.waitForStarted();
              setSerial.waitForReadyRead();
              setSerial.waitForFinished();
              
              QProcess *inputList= new QProcess(this);
              inputList-> setProgram("/bin/bash");
              inputList-> start();
              inputList->write("xinput list");
              inputList->write("\n");
              inputList->closeWriteChannel();
              
              ui-> text Edit->insertPlainTextEdit( inputList-> readAllStandardOutPut());
              }
              

              I even used readyReadStandardOutput signal once but it seems like the problem is s.th else.
              I would appreciate if someone help me

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #7

              @TahmDev said in Qprocess runs correctly in debug but in release mode it doesn't run correctly:

              QProcess *inputList= new QProcess(this);
              inputList-> start();

              I seem to be the only person commenting on this, but what does this do? You are using overload https://doc.qt.io/qt-5/qprocess.html#start-2, which says

              Starts the program set by setProgram() ...

              and https://doc.qt.io/qt-5/qprocess.html#setProgram says:

              Set the program to use when starting the process. This function must be called before start().

              Show me how you (apparently) reckon inputList->write("xinput list"); runs xinput list? So I don't understand how you are running any program at all for this? Whether this is connected to debug/release I cannot say....

              [EDIT See my topic https://forum.qt.io/topic/118969/qprocess-with-no-program-to-run for this issue which conused me and may confuse any reader of the code!]

              1 Reply Last reply
              0
              • SGaistS SGaist

                Please take the time to read the class documentation:

                QProcess::errorOccurred
                QProcess::error
                etc.

                As for your code, it will run faster in release than debug mode. The way you wrote your second QProcess code is wrong. You assume that it has ended after the call to closeWriteChannel which is an error.

                You should learn how to use it in asynchronous mode.

                By the way, you are "leaking" QProcess objects there. They will only be destroyed when the parent is which means you can still fill memory with them each time you call on_button_clicked.

                T Offline
                T Offline
                TahmDev
                wrote on last edited by
                #8

                @SGaist I read the documents, I'm not a pro, but I wrote many connect signal slots for error occured and state changed to my processes ... Everything works fine but the problem is that the second processes starts soon...if you can help me I would be grateful

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  TahmDev
                  wrote on last edited by
                  #9

                  Guys thanks for all your advices ...I figured out the problem, the linux command related to inputattach makes inputattach to run in background and returns to qt so fast that the attachment has not happened yet.
                  I added a timer to my program and after 1000ms the other process will be initiated.
                  Everything is fine then

                  SGaistS 1 Reply Last reply
                  1
                  • T TahmDev

                    Guys thanks for all your advices ...I figured out the problem, the linux command related to inputattach makes inputattach to run in background and returns to qt so fast that the attachment has not happened yet.
                    I added a timer to my program and after 1000ms the other process will be initiated.
                    Everything is fine then

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @TahmDev said in Qprocess runs correctly in debug but in release mode it doesn't run correctly:

                    I added a timer to my program and after 1000ms the other process will be initiated.
                    Everything is fine then

                    You know that this is going to haunt you ?
                    Did you check my suggestion of using QProcess asynchronous nature to manage the commands you are running ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    T 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      @TahmDev said in Qprocess runs correctly in debug but in release mode it doesn't run correctly:

                      I added a timer to my program and after 1000ms the other process will be initiated.
                      Everything is fine then

                      You know that this is going to haunt you ?
                      Did you check my suggestion of using QProcess asynchronous nature to manage the commands you are running ?

                      T Offline
                      T Offline
                      TahmDev
                      wrote on last edited by
                      #11

                      @SGaist as a matter of fact it did... Then I used Qthread::msleep(500);
                      I will try using it asynchronously today and get back to you with the result...

                      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