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. No content from readAll()

No content from readAll()

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.1k 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.
  • J Offline
    J Offline
    jocala
    wrote on last edited by
    #1

    I'm trying to check existence of a file on an android device via the adb command. The attempt to grab the console output via command=readAll() returns empty every time.

    @
    QProcess *check_busybox2=new QProcess;
    check_busybox2->setProcessChannelMode(QProcess::MergedChannels);
    cstring = adb + " -s " + daddr+port + " shell ls /system/xbin/which";
    check_busybox2->start(cstring);
    check_busybox2->waitForFinished(-1);
    command=check_busybox2->readAll();
    delete check_busybox2;

           if (command.contains("No such file or directory"))
             QMessageBox::information( this,"","Busybox uninstalled " + command);
           else
            QMessageBox::critical( this,"","Busybox not uninstalled! " + command);
    

    @

    I can run the command from the console and get expected output, capture the output to a file, etc. Why is readAll() returning an empty string?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      Chances are that either:

      the command you are giving QProcess, cstring) is not correct; or

      the environment in which you "run the command from the console and get expected output" and the one that QProcess is working with are not the same.

      In either case, you should check QProcess::error() and QProcess::exitStatus() for clues.

      My money is on option 1: it looks like you are pasting the address and port number together without intervening whitepsace/punctuation. You should consider the other QProcess::start() overload.

      BTW: There seems to be no reason to allocate the QProcess object on the heap.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jocala
        wrote on last edited by
        #3

        You have a sharp eye, thanks:)

        BTW: There seems to be no reason to allocate the QProcess object on the heap.

        So, like this?

        @
        QProcess check_dir;
        check_dir.setProcessChannelMode(QProcess::MergedChannels);
        cstring = adb + " -s " + daddr + port + " shell ls /system/xbin/which";
        check_dir.start(cstring);
        check_dir.waitForFinished(-1);
        command=check_dir.readAll();
        @

        If I did it correctly above, why is this method better?

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

          Hi,

          AFAIK, when calling start and having arguments, you should use the same pattern as described "here":http://qt-project.org/doc/qt-5/qprocess.html#details
          Passing parameters can be tricky

          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
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #5

            [quote author="jocala" date="1404621560"]
            If I did it correctly above, why is this method better? [/quote]

            Allocation on the stack means you do not have worry about (i.e. cannot forget) freeing the memory you allocated.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jocala
              wrote on last edited by
              #6

              Allocation on the stack means you do not have worry about (i.e. cannot forget) freeing the memory you allocated.

              That would be the code below? (or are there other steps?)

              @
              delete processname;
              @

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

                Indeed, but in the present case, it's not useful to allocate QProcess on the heap to delete it right after since it won't survive the function.

                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
                • J Offline
                  J Offline
                  jocala
                  wrote on last edited by
                  #8

                  Thanks for the feedback. Learn a little more every day :)

                  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