Qt World Summit: Submit your Presentation

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

  • 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);
       qInfo() << "error" << process.error(); // QProcess::UnknownError

    Does anyone know what I'm doing wrong?

  • @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.

  • @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?

  • Lifetime Qt Champion

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

  • @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.

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

    I tried the following:


    But always the same error...

  • Lifetime Qt Champion

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

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

Log in to reply