Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Why does the command 'touch -t' via QProcess only works for Android 7+?
QtWS25 Last Chance

Why does the command 'touch -t' via QProcess only works for Android 7+?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
8 Posts 3 Posters 759 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.
  • PowerNowP Offline
    PowerNowP Offline
    PowerNow
    wrote on last edited by PowerNow
    #1

    For my Android App I need to edit my photos and keep the original date and time for Android 5.1 - 9. But the timestamp is only changed for Android 7+.

    QString fileDate = reader.text("date");
    QDate date = QDate::fromString(fileDate, "yyyy-MM-dd");
    
    QString fileTime  = reader.text("time");
    QTime time = QTime::fromString(fileTime, "HH:mm:ss");
    
    QString dateTimeStrg;
    if(date.isValid() && time.isValid()) {
       QDateTime dateTime(date, time);
    
       dateTimeStrg = dateTime.toString("yyMMddhhmm.ss");
    
       QProcess process;
       process.start("touch", QStringList() << "-t" << dateTimeStrg << filePath);
       process.waitForFinished();
    
       qInfo() << "error" << process.error(); // QProcess::UnknownError
    }
    

    Does anyone know what I'm doing wrong?

    JonBJ 1 Reply Last reply
    0
    • PowerNowP PowerNow

      For my Android App I need to edit my photos and keep the original date and time for Android 5.1 - 9. But the timestamp is only changed for Android 7+.

      QString fileDate = reader.text("date");
      QDate date = QDate::fromString(fileDate, "yyyy-MM-dd");
      
      QString fileTime  = reader.text("time");
      QTime time = QTime::fromString(fileTime, "HH:mm:ss");
      
      QString dateTimeStrg;
      if(date.isValid() && time.isValid()) {
         QDateTime dateTime(date, time);
      
         dateTimeStrg = dateTime.toString("yyMMddhhmm.ss");
      
         QProcess process;
         process.start("touch", QStringList() << "-t" << dateTimeStrg << filePath);
         process.waitForFinished();
      
         qInfo() << "error" << process.error(); // QProcess::UnknownError
      }
      

      Does anyone know what I'm doing wrong?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @PowerNow
      This will not be an error from using QProcess nor with your code. You should look at the touch -t command you are using and the Android version. Maybe the option changed or the format of the argument?

      If touch is perhaps reporting an error you are not checking for it. You should check for error codes, and read stdout/err from QProcess to see if a message is being sent there.

      1 Reply Last reply
      2
      • PowerNowP Offline
        PowerNowP Offline
        PowerNow
        wrote on last edited by PowerNow
        #3

        @JonB Thks! I forgot to mention that I check the error via process.error(), it's for all versions QProcess::UnknownError, the default value. Yes if it depends from the Android Version, where can I find this?

        jsulmJ JonBJ 2 Replies Last reply
        0
        • PowerNowP PowerNow

          @JonB Thks! I forgot to mention that I check the error via process.error(), it's for all versions QProcess::UnknownError, the default value. Yes if it depends from the Android Version, where can I find this?

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

          @PowerNow Did you check stderr/stdout as @JonB suggested?

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

          1 Reply Last reply
          1
          • PowerNowP PowerNow

            @JonB Thks! I forgot to mention that I check the error via process.error(), it's for all versions QProcess::UnknownError, the default value. Yes if it depends from the Android Version, where can I find this?

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @PowerNow
            I meant you need to look at something like https://doc.qt.io/qt-5/qprocess.html#readAllStandardError (and readAllStandardOutput() too just in case).

            For the Android version differences, I don't use Android, so I'd have to Google, which is what you would need to do. Or find an Android forum to ask.

            1 Reply Last reply
            1
            • PowerNowP Offline
              PowerNowP Offline
              PowerNow
              wrote on last edited by
              #6

              I just checked it with readAllStandardError() and get for Android 5x,6x:
              "touch: invalid timestamp specified\n"

              I tried the following:

              [[CC]YY]MMDDhhmm[.ss]
              "201912051120.11"
              [YY]MMDDhhmm[.ss]
              "1912051120.11"
              MMDDhhmm[.ss]
              "12051120.11"
              MMDDhhmm
              "12051120"

              But always the same error...

              jsulmJ JonBJ 2 Replies Last reply
              0
              • PowerNowP PowerNow

                I just checked it with readAllStandardError() and get for Android 5x,6x:
                "touch: invalid timestamp specified\n"

                I tried the following:

                [[CC]YY]MMDDhhmm[.ss]
                "201912051120.11"
                [YY]MMDDhhmm[.ss]
                "1912051120.11"
                MMDDhhmm[.ss]
                "12051120.11"
                MMDDhhmm
                "12051120"

                But always the same error...

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

                @PowerNow Then you need to check what formats that version of touch supports.

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

                1 Reply Last reply
                1
                • PowerNowP PowerNow

                  I just checked it with readAllStandardError() and get for Android 5x,6x:
                  "touch: invalid timestamp specified\n"

                  I tried the following:

                  [[CC]YY]MMDDhhmm[.ss]
                  "201912051120.11"
                  [YY]MMDDhhmm[.ss]
                  "1912051120.11"
                  MMDDhhmm[.ss]
                  "12051120.11"
                  MMDDhhmm
                  "12051120"

                  But always the same error...

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by
                  #8

                  @PowerNow
                  ...which is exactly what I expected was happening, and hence why you always need to capture any output from commands run via QProcess...

                  1 Reply Last reply
                  1

                  • Login

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