Project hangs on QProcess::start when starting QtAssistant
-
I am using
QProcess::start
to launchQt 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 atQProcess:start
function when trying to start process. The code is:show()
function(public):if (!run()) return false; QByteArray ba("setSource "); ba.append("qthelp://insyn_help/doc/"); 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()) { proc->start(app,args); if (!proc->waitForStarted()) { m_exitCode = 1; emit closed(); return false; } }
This code is a part of
AssistantLauncher
class which was registered usingqmlRegisterType
and added tomain.qml
as a member of application window. My programm doesn't touch it anywhere (except calling a methodshow()
). It is separate object (except it is a part ofappWindow
). The question is why does the process can not start only after my programm did some work? And whyQProcess::start
even dont have timeout. -
The answer is to do not use
fork()
because it is dangerous in big projects. More at http://www.evanjones.ca/fork-is-dangerous.html .posix_spawn
also hangs my project. Now i decided tofork()
new process at the beginning and send commands to it through the pipe. -
@Maxim-Skvortsov
I admit I know nothing about your situation. ButQProcess::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 itproc->waitForStarted()
, because I can only guess it could be the latter.... -
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 knowQProcess
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 classAssistantLauncher
, which was wrote using Qt's manual about it's usage with custom help project file. That class was registered for qml inmain.cpp
usingqmlRegisterType
and then added tomain.qml
as a part ofApplicationWindow
object. I already tried to delete and createproc
every timerun()
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 beQProcess::start("cmd /c dir")
if you are on Windows orQProcess::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 investigateQProcess::start
code. I don't really know what am i looking for and what can happen insideQProcess
, that leads to hang. -
@JonB I moved
proc->start(app,args);
to the child process, which i getting by usingfork()
and now my programm hangs onpid_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 onfork()
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.P.S.
If you are using a debugger to determine you are "hanging" onfork()
, for reasons I do not have time to go into now there is a chance your debugger might have trouble onfork()
and not correctly step over it to the next statement, so just bear that possibility in mind. -
@JonB
I also tried to move execution toQThread
, but it didn't work. Program is still hanging onproc->start(app,args);
. Also i tried to useQProcess::startDetatched
,QProcess::execute
andsystem()
. 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 usinghtop
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 thefork()
before the subsequentexec()
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 http://www.evanjones.ca/fork-is-dangerous.html .posix_spawn
also hangs my project. Now i decided tofork()
new process at the beginning and send commands to it through the pipe.