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. Program hangs
QtWS25 Last Chance

Program hangs

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.3k 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 have an issue where my program appears to hang. The code below gets a filename from the user and builds a string that is passed to QProcess. A progress bar is started to give the user a visual clue that the process is running. The progress bar is hidden when the process completes.

    The issue is that very rarely the progress bar will max out and no completion is sent back to the user. The program just sits. This doesn't happen often, out of about 2000 users, I've gotten a half-dozen sporadic reports. And with those reporting, it's not a consistent problem. It has never happened to me personally.

    If you see anything in the code that could be causing this I'd appreciate it if you could point it out. If you have a solution that you can show in code it would be very helpful.

    Thanks!

    @
    QString RunProcess(QString cstring)
    {
    QProcess run_command;
    run_command.setProcessChannelMode(QProcess::MergedChannels);
    run_command.start(cstring);

    run_command.waitForStarted();

    while(run_command.state() != QProcess::NotRunning)
    qApp->processEvents();

    QString command=run_command.readAll();

    return command;
    }

    void MainWindow::on_sideload_Button_clicked()
    {

    if (!isConnected)
       { QMessageBox::critical(
             this,
             tr("adbFire"),
             tr("Device not connected"));
          return;
    }
    
    
    QElapsedTimer rtimer;
    int nMilliseconds;
    rtimer.start();
    

    QString fileName = QFileDialog::getOpenFileName(this,
    tr("Select app to install"), sldir , tr("APK Files (*.apk)"));

    if (!fileName.isEmpty() )
    {
    
    QFileInfo finfo(fileName);
    sldir = finfo.absolutePath();
    
    QMessageBox::StandardButton reply;
      reply = QMessageBox::question(this, "Install", "Install "+fileName+"?\n",
                                    QMessageBox::Yes|QMessageBox::No);
      if (reply == QMessageBox::Yes)
      {
    
    
          ui->progressBar->setHidden(false);
          ui->progressBar->setValue(0);
    
          QTimer *timer = new QTimer(this);
          connect(timer, SIGNAL(timeout()), this, SLOT(TimerEvent()));
          timer->start(tsvalue);
    
          QString cstring = adb + " install -r " + '"'+ fileName+'"';
    
          QString command=RunProcess(cstring);
    
           ui->progressBar->setHidden(true);
    
           logfile(cstring);
           logfile(command);
    
           nMilliseconds = rtimer.elapsed();
           logfile("process time duration: "+ QString::number(nMilliseconds/1000)+ " seconds" );
    
    
           if (command.contains("Success"))
    
               QMessageBox::information(this,"","Installed");
              else      
               QMessageBox::critical(this,"","Install failed");
    
    }
    

    }

    }

    @

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      Qub1
      wrote on last edited by
      #2

      Well I'm not sure but I think it most likely has something to do with the while loop inside RunProcess:
      @while(run_command.state() != QProcess::NotRunning)
      qApp->processEvents();@
      Maybe the process you're running doesn't cause Qt to emit a NotRunning signal? Or maybe it emits another signal when it finishes, like an idle signal (this is all speculation).

      Maybe it would be safer to use:
      @while(run_command.state() == QProcess::Running)
      qApp->processEvents();@
      That way it takes into account any other finished states the process might have.

      But that's just a guess. Hope it helps.

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

        Thanks for the speculation. I'll give this a shot.

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

          Hi,

          You should check the return value from waitForStarted to see whether the program really started

          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