Solved QProcess starting separate Qt application based on QWidget class
-
Hello everyone, this is my first post on the forum!
I am the beginner in Qt and I am struggling with starting the application in Windows, which I have written with Qt, the application which I am trying to start (child) is based on QtWidget class (32-bit) and I am starting it with program (parent) based on QtMainWindow class (64-bit).
The program is starting correctly with start(), I can see it in the Task Manager, state() command returns 2 (QProcess::Running) but it does not start any window. Then I tried the startDetached(), but it also failed.
I know, that the program does produce the output, it does so, when I start this child process separately so in order to check if the program is actually running I was checking to children stdout withconnect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(processOutput())); // connect process signals with your code connect(process, SIGNAL(readyReadStandardError()), this, SLOT(processOutput())); // same here
and
void BroadcasterGUI::processOutput() { qDebug() << process->readAllStandardOutput(); // read normal output qDebug() << process->readAllStandardError(); // read error channel }
but no output was produced. Tried also with
process->setStandardOutputFile("D:\\<Program path>\\output.txt"); process->start(exeFile);
the output file is created, but no input appears in it.
And still trying something as simple asQProcess *process = new QProcess(parent); QString program = "\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\""; process->start(program);
starts the notepad++ without any problems.
I will be very helpful for any indications what should I do different to solve this issue, because it seems for now, that I will need to start the application in Qt in a different, separate way without incorporating QProcess... It is always possible, but I would be happy to be able to use the features the QProcess provides.
-
@Jendker
please try startDetached
process->startDetached() -
@Jendker said in QProcess starting separate Qt application based on QWidget class:
The program is starting correctly with start(), I can see it in the Task Manager, state() command returns 2 (QProcess::Running) but it does not start any window. Then I tried the startDetached(), but it also failed.
Checked, it also does not solve the issue.
-
Have you deployed both applications with their own Qt libraries?
Most likely the problem is that your 32bit application can't find correct Qt libraries. -
@tomma
In order to start 32bit application I am changing the working directory so that the application does find the Qt library, if I do not set this path I get an error on startup, so I guess this thing is solved properly. If I should check it in a specific way please let me know! -
@Jendker said in QProcess starting separate Qt application based on QWidget class:
process->setStandardOutputFile("D:\<Program path>\output.txt");
process->start(exeFile);Try QFile file("D:\<Program path>\output.txt");
if(file.exists){
Verify the file if you have this address is correct.
} -
@Taz742
If I understand your post properly: yes, the path is correct, the file is created in the given directory, but it reamains empty after running the program. -
@Jendker
Hi
If you go to the location of the application and click it.
Does it then start normally ? -
@mrjj
Hi
Yes, it does start without any problems.Do give you some details which may be relevant:
- the child process has subsystem: Windows defined and is written with VS Tools Plugin
- I am starting the parent with the console in the following way (as I am working in VS):
#ifdef DEBUG // detach from the current console window // if launched from a console window, that will still run waiting for the new console (below) to close // it is useful to detach from Qt Creator's <Application output> panel FreeConsole(); // create a separate new console window AllocConsole(); // attach the new console to this application's process AttachConsole(GetCurrentProcessId()); // reopen the std I/O streams to redirect I/O to the new console freopen("CON", "w", stdout); freopen("CON", "w", stderr); freopen("CON", "r", stdin); #endif
And was trying to start the child with such console activated and not, it did not make any difference, the window did not appear.
-
@Jendker said in QProcess starting separate Qt application based on QWidget class:
, the window did not appear.
Window being a console (cmd) window ?
-
@mrjj
No, the child is the QtWidget class based application, I was trying to start it with start() and startDetached() and the appplication only appeared in Task Manager in both cases. When I start it manually it works without any problems. -
@Jendker
it must be something simple then.
The program you trying to start do have a complete deployment folder with all needed Dlls? -
@mrjj
Yes, it does start without any problem when I am doing it manually. I guess that means, that it has all needed Dlls?I tested and simple console Hello World program is writing to the output file without any problem, but the child QtWidget program which has also std output does not write anything to the file. The problem is that, the program does not terminate, as it is working in loop and is being destroyed before the termination when closing parent application (when starting with start() ). Maybe because of it it does not even write anything to the output file?
EDIT: It is possible that I found the issue, please just let me work on it for now to check it.
EDIT2: Yes, it seems, that when I was starting the parent, there was something wrong with semaphore what was blocking the other application to start... I was trying to port the standard C++ project (where it was working fine) to Qt and it seems that I messed something up with it. Sorry for the confusion, if I will have any further problems with it, let me continue to ask in this topic.
-
@Jendker said in QProcess starting separate Qt application based on QWidget class:
Super. I cross fingers you found it.. Maybe because of it it does not even write anything to the output file?
Do you call flush from time to time on the file?
Else yes, if it dont terminate , it might never flush/write to the file.I guess that means, that it has all needed Dlls?
You can check that by renaming the Qt folder and then try to start it.
This way it must use its included dlls and not the one it can find in the Qt folder. -
@mrjj
Thank your for your input :) My case is solved, therefore I match question as answered. -
@Jendker I would be nice from you to explain how was resolved.
-
@Juampa
Hi and welcome the forums.
Which part of the pretty long post ?
You try start a Qt application with Process ?