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. QProcess inside QtConcurrent::mapped - no slots called
Forum Updated to NodeBB v4.3 + New Features

QProcess inside QtConcurrent::mapped - no slots called

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 298 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.
  • S Offline
    S Offline
    Stach
    wrote on last edited by
    #1

    The following code works - "echo" program is called for "abc" and "def", the results are collected and printed.

    If timer delay is set to 0, it stops working.

    "echo" is called, even the readLine (if called) would return the right content, but "finished" slot is never called. process.state() shows that the process is still running.

    Why?

    QFuture<QString> tfuture;
    QFutureWatcher<QString> twatcher;
    
    QString ftest(QString a){
        QProcess process;
        QEventLoop loop;
        QObject::connect(&process, &QProcess::finished, [&](int exit_code) {
            qDebug() << "OK " << a << " " << exit_code;
            loop.exit(0);
        });
        QTimer::singleShot(1, [&] {
            qDebug() << "STARTING " << a;
            process.start("echo", {{"ECHO ", a}});
        });
        loop.exec();
        return process.readLine();
    };
    
    void tfinished() {
        QList<QString> result = twatcher.future().results();
        qDebug() << "finished " << result;
    }
    
    ...
    QStringList params = {{"abc", "def"}};
    tfuture = QtConcurrent::mapped(params, ftest);
    connect(&twatcher, &QFutureWatcher<QString>::finished, this, &tfinished);
    twatcher.setFuture(tfuture);
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      What exact Qt version do you use?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Stach
        wrote on last edited by
        #3

        6.4.2 open source, mac os

        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