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 - strange behavior

QProcess - strange behavior

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.5k 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.
  • A Offline
    A Offline
    Adrian.Aioanei
    wrote on last edited by
    #1

    Hey guys,

    I have meet a strange problem with QProcess. I have an executable how write some data into a file. If i run the executable from widows explorer it works and write data to the file but if i use QProcess, the executable starts but at the end do not write data to the file.
    I have read on the internet about this thing and some people say it could be block from the antivirus but i turn of and still the same results.
    When i start the process i use something like this

    proc.start("Exe path", QIODevice::ReadWrite);
    

    Have anyone some idea about this think?
    Thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DonMirkoni
      wrote on last edited by
      #2

      You can try like this

          QString path = QCoreApplication::applicationDirPath ();
          path.append("/nameapp.exe");
          QString path1="file:///";
          QString path2 = path1+path;
          QDesktopServices::openUrl(QUrl(path2, QUrl::TolerantMode));
      
      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        You should add handling for the standard output and standard error channels of your QProcess to see what is going on.

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

        1 Reply Last reply
        2
        • A Offline
          A Offline
          Adrian.Aioanei
          wrote on last edited by Adrian.Aioanei
          #4

          This works in some way but my application crash because doesn't find any data in the file to print to the interface. I have a function for a pushed button and looks like this:

              QString path = QCoreApplication::applicationDirPath ();
              path.append("/testExecutabele.exe");
              QString path1="file:///";
              QString path2 = path1+path;
              QDesktopServices::openUrl(QUrl(path2, QUrl::TolerantMode));
          
              this->proc.start(path2, QIODevice::ReadWrite);
              this->proc.waitForFinished(-1);
              AddData data;               //class
              data.insertDataToLabels(); //function how read data from the file created by testExecutabele.exe
          

          In textExecutabele.exe i have put a delay of 5000 ms. In a normal way when i push the button i will need to wait 5 sec before to crash if doesn't find data in file but in this case if in the file is empty it crash in the moment when i push the button. So is possible to be a probleme at this->proc.waitForFinished(-1); ? If i delete last tow line from the function (method from insert data to labels) everything works fine, the executable run and the file is created.
          The entire application run on the same thread, so all the code will be executed sequentially, write?

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

            Your process won't start, it's not a valid path to start an application with QProcess.

            You should check the result from exitCode.

            And you should also check the code from AppData, an empty file should not be able to crash your application, that's a pretty bad flaw.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - 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