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. QProcess to update android system date/time locks GUI

QProcess to update android system date/time locks GUI

Scheduled Pinned Locked Moved Solved Mobile and Embedded
6 Posts 2 Posters 2.4k 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.
  • D Offline
    D Offline
    DoughBoy
    wrote on last edited by
    #1

    Hello,

    I have an interesting issue that I have no idea how to tackle. I've tried several methods to change an android's system date/time and each method, when successful, locks my GUI for a solid minute. I see that the change happens instantly because of the android status bar reflecting the changed time. But, it doesn't explain why my GUI would get locked up.

    Here's the code to change the system date/time

    CallSystemFn(QString("su -c date -s ").append(altDateTime.toString("yyyyMMdd.hhmmss")))
    

    The [CallSystemFn(QString cmdStr)] code has been many different versions:

    /*  Version 1  */
    FILE *cmdFile = popen(cmdStr.toStdString().c_str(), "r");
    //Ensure a system output file exists
    if(cmdFile) {
        //Read the system output file
        char tmpBuffer[1024];
        while(fgets(tmpBuffer, sizeof(tmpBuffer), cmdFile) != NULL)
            outputStr.append(tmpBuffer);
        //Trim the last character from the string - it's a new line character
        outputStr.remove(outputStr.length()-1, 1);
    
        //Close the output data file
        pclose(cmdFile);
    }
    
    /*  Version 2  */
    QProcess cmdFile;
    cmdFile.start(cmdStr);
    cmdFile.waitForFinished();
    outputStr.append(cmdFile.readAll());
    cmdFile.close();
    
    /*  Version 3  */
    QProcess::startDetached(cmdStr);
    

    I have thought about running a QThread object to set the system date/time, but that's what "Version 3" pretty much does. Has anyone ran into a similar problem and if so, how did you solve it?

    Thanks to all for their help!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      So, even the third version locks up the GUI?

      (Z(:^

      D 1 Reply Last reply
      0
      • sierdzioS sierdzio

        So, even the third version locks up the GUI?

        D Offline
        D Offline
        DoughBoy
        wrote on last edited by
        #3

        @sierdzio
        Yes, even version 3, locks up the GUI. It's the strangest thing right?! My next approach is to create a QThread object that can run simultaneously to the GUI thread, to change the system date/time. I am hoping this idea won't cause any issues to my GUI thread. Do you think this would be a good attempt? Can you offer any other suggestions I should try first?

        Thanks!

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Yes, it is very weird that a separate process can block the GUI.

          Since this is about changing the date, maybe you could use some native Android calls (in Java), and invoke them through JNI? Qt has some convenience functions to help you with that, see the QtAndroidExtras module.

          (Z(:^

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DoughBoy
            wrote on last edited by
            #5

            After much digging around, I found out that it's not setting the system Date/Time that blocks the GUI thread. It's my QTimer's that are the culprit. It seems, when these objects are created, they take on the system's date/time stamp and any modification of the system date/time doesn't alter these original stamps. SO, when I'm waiting for my QTimers to fire off, they end up playing a "catch up" game with the altered system's date/time - hence the locked GUI that I've been experiencing.

            I hope this sheds some light for anyone else who runs into this same problem.

            1 Reply Last reply
            1
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Congrats on solving this issue! Or at least finding the root cause.

              (Z(:^

              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