Important: Please read the Qt Code of Conduct -

Project hangs on QProcess::start when starting QtAssistant

  • I am using QProcess::start to launch Qt Assistant with my custom help project file. It works fine until i load project(not help project file) to my programm. Programm generates images from specific data using custom library. Even when all processes ends and i see generated images and nothing else happens, when i trying to launch Qt Assistant, my programm hangs at QProcess:start function when trying to start process. The code is:

    show() function(public):

    if (!run())
        return false;
    QByteArray ba("setSource ");
    proc->write(ba + page.toLocal8Bit() + '\n');
    return true;

    run() function(private):

    if (!proc)
        proc = new QProcess();
    if (proc->state() == QProcess::Running)
        return true;
    QString app = QString(QT_BIN_DIR) + QDir::separator() + QString("assistant");
    QString path = QString(PREFIX) + QString(HELP_INSTALL_PATH) + QString("/help_project.qhc");
    QStringList args;
    args << QLatin1String("-collectionFile")
         << QLatin1String(path.toLatin1())
         << QLatin1String("-enableRemoteControl");
    QFileInfo help_project(path);
    if (help_project.exists()) {
        if (!proc->waitForStarted()) {
            m_exitCode = 1;
            emit closed();
            return false;

    This code is a part of AssistantLauncher class which was registered using qmlRegisterType and added to main.qml as a member of application window. My programm doesn't touch it anywhere (except calling a method show()). It is separate object (except it is a part of appWindow). The question is why does the process can not start only after my programm did some work? And why QProcess::start even dont have timeout.

  • The answer is to do not use fork() because it is dangerous in big projects. More at . posix_spawn also hangs my project. Now i decided to fork() new process at the beginning and send commands to it through the pipe.

  • @Maxim-Skvortsov
    I admit I know nothing about your situation. But QProcess::start() does not have a timeout because I don't think it has anything to wait for. It's only starting off a new OS process, it does not wait for anything to happen. In particular it does not care what the subprocess does, so at least theoretically it shouldn't matter that it's Qt Assistant or what that actually does or does not perform.

    OOI, is it actually the proc->start(app,args); which you say "hangs", or is it proc->waitForStarted(), because I can only guess it could be the latter....

  • @JonB It is actually proc->start(app,args);. The programm doesn't reach proc->waitForStarted() when it hangs.
    I tried to launch something else (chromium-browser, for example), but the same thing happened.

  • @Maxim-Skvortsov

    It is actually proc->start(app,args);
    I tried to launch something else (chromium-browser, for example), but the same thing happened.

    Quick answer: then there is something very wrong in your situation....

    I suggest you start again on a tiny, standalone piece of code. (For example, your code allows for proc already existing, I don't know what path it actually follows....) Pick a simple case first, like a non-interactive program, then build up to what you want. We definitely know QProcess stuff works, so we need to know just what is different in your situation....

  • @JonB About path of proc. As i mentioned in description, it is a part of class AssistantLauncher, which was wrote using Qt's manual about it's usage with custom help project file. That class was registered for qml in main.cpp using qmlRegisterType and then added to main.qml as a part of ApplicationWindow object. I already tried to delete and create proc every time run() function used, but it doesn't help.
    About "pick a simple case" way. As i said, i already have a project and it is pretty big and the problem occurs only if my project did some job. If i just launch my programm and press F1, help works fine. But when i load a project to my programm, while it is calculating or when all calculations done, help hangs. My programm creates many threads(number is restricted by user) while calculating. Do not know if it can influence somehow.

  • @Maxim-Skvortsov
    I'm sorry I have no idea what you're saying or how it is relevant. QProcess::start() is an OS call to get it to launch a sub-process. A simple case might be QProcess::start("cmd /c dir") if you are on Windows or QProcess::start("ls") if Linux/Mac.

  • @JonB Yes, i understand that. And it works. Until my program doesn't do any job )
    I think i'll try to investigate QProcess::start code. I don't really know what am i looking for and what can happen inside QProcess, that leads to hang.

  • @JonB I moved proc->start(app,args); to the child process, which i getting by using fork() and now my programm hangs on pid_t child = fork(). So the problem is that new process can not be created. I am investigating that problem...

  • @Maxim-Skvortsov
    Just so you understand. If you are hanging on fork() it has not got as far as executing whatever sub-process you are asking it to execute --- that would come next, immediately after returning from the fork call. fork() really should not hang! If it does, one thought would be out of spare memory? But really it would/should return an error code to the parent if there is a problem.

    If you are using a debugger to determine you are "hanging" on fork(), for reasons I do not have time to go into now there is a chance your debugger might have trouble on fork() and not correctly step over it to the next statement, so just bear that possibility in mind.

  • @JonB
    I also tried to move execution to QThread, but it didn't work. Program is still hanging on proc->start(app,args);. Also i tried to use QProcess::startDetatched, QProcess::execute and system(). In all cases when i press pause, after i asked program to open help, debugger stops on help execution line. Also i monitor processes in console using htop and there was no new processes when i tried to open help. And one core of CPU had been loaded by 100% every time when program hangs on help execution.

  • @Maxim-Skvortsov
    One more time: as I have said, from what you have written it appears that the fact you are trying to invoke some "Qt Assistant Help" program is irrelevant, in that the code seems to get stuck in the fork() before the subsequent exec() of the program. I suggest you try with something else simpler (like I suggested earlier) and state clearly whether that too does indeed fail. Then you can remove complexity for this issue by clarifying that it has nothing to do with what application you are trying to spawn.

  • The answer is to do not use fork() because it is dangerous in big projects. More at . posix_spawn also hangs my project. Now i decided to fork() new process at the beginning and send commands to it through the pipe.

Log in to reply