QProcess unexpectedly finished
-
@krist said in QProcess unexpedtedly finished:
QProcess *myProcess = new QProcess(parent);
Your
parent
is an invalid object (not initialized withnew
). Do this instead:QProcess *myProcess = new QProcess(this);
Here
this
is yourMainWindow
- it will act as parent for your process object. -
Thank you for the answer sierdzio.
I have updated my code becoming this
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QProcess> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_clicked() { QProcess *myProcess = new QProcess(this); QString program = "./home/krist/Qt5.13.2/examples/Qt-5.13.2/gui/analogclock"; QStringList arguments; arguments << "-style" << "motif"; myProcess->start(program, arguments); }
but when i klik the UI button, nothing is runnable.
when I look at the analogclock example file, that path is true.
Inside that path there are only 3 files:- analogclock.pro
- analogclock.pro.user
3.main.cpp
sory, I'm new about this qt
-
QProcess can only run a binary file. You need to compile AnalogClock first, then change your path to point exactly to the resulting binary file.
-
I have run the analogClock, but i don't know where the binary file go
can you please guide me?
or maybe do you have a refrence video to do it?
I am very appreciated itafter i run, there is appear build-analogclock ... debug
is it the binary file go?
and inside it, there are 7 file in itthank you
-
Go into that build directory, there will be
analogclock
file in there (it will have executable permissions, easy to spot if you runls -aGl
in the directory, or by looking at icon in some file manager) - that's your binary. -
@krist said in QProcess unexpectedly finished:
I have run the analogClock, but i don't know where the binary file go
What does "run" mean? You have to build --- compile & link --- the
analogclock
project, either for debug or for release. That puts the executable in a directory as specified in the.pro
file/look at your Qt Creator settings for building. That is what you need to execute. No, there is no "reference video" for this. It's what building from source code is all about.after i run, there is appear build-analogclock ... debug
is it the binary file go?Did you try looking in that directory, for an executable named
analogclock
?From the output you showed earlier:
Starting /home/krist/qt_proj/build-try_QProcess-Desktop-Debug/try_QProcess ...
While for yourQProcess
command you show
./krist/QT5.13.2/examples/QT-5.13.2/gui/analogclock
How are these two paths related? Why have you placed a./
at the start of that? What is your current directory? I would recommend only using absolute paths, not relative, so you know what is going on. -
thank you for the answers
Starting /home/krist/qt_proj/build-try_QProcess-Desktop-Debug/try_QProcess ...
is mine project where i make.
and the QT5.13.2 is where the analogclock file is
what i mean run is build and run (click on the little hammer in the left below qt and the play icon).
QProcess *myProcess = new QProcess(this); QString program = "/home/krist/Qt5.13.2/examples/Qt-5.13.2/gui/build-analogclock-Desktop_Qt_5_13_2_GCC_64bit-Debug/analogclock"; QStringList arguments; arguments << "-style" << "motif"; myProcess->start(program, arguments);
I have found the analogclock at file build-analogclock-Desktop ...
but when i source it like below, nothing happened
Is there anything wrong? -
Probably the example fails to run because Qt libraries are not found by
ldd
. You need to setLD_LIBRARY_PATH
for it to work.To get the actual error messages or warnings coming from QProcess, make sure you connect to errorOccured signal and get all output from stderr.
-
I just realied that every time I build and run there is always a notification like this :
15:25:54: Starting /home/krist/qt_proj/build-try_qprocess1-Desktop-Debug/try_qprocess1 ... 15:25:58: The program has unexpectedly finished. 15:25:58: The process was ended forcefully. 15:25:58: /home/krist/qt_proj/build-try_qprocess1-Desktop-Debug/try_qprocess1 crashed.
Is it the error that you looking for?
-
@krist said in QProcess unexpectedly finished:
Is it the error that you looking for?
It's not me looking for errors here, it's you :-)
15:25:58: The program has unexpectedly finished.
No, this tells us nothing. We need more information. Run your app with a debugger (F5), it will show you where the crash occurs.
-
You've commented out the
on_pushButton_clicked()
slot, so it's not crashing. -
Does it crash when you click the button? The screenshot does not show any crash.
-
@krist
I can see by enlarging your image that you are still not supplying the correct path for the subprocess. Nor does it even have the executable you wish to run. There is no point telling us here your code contains a certain string if it does not actually use that string. You need to understand the absolute basics about paths if you expect to develop code....Further, you should read the
QProcess
documentation and e.g. both check return results anderrorOccurred
slot if you are having trouble running a process and expect to get error status back. -
@krist said in QProcess unexpectedly finished:
I use the path based on projects analogClock
No, you don't. The screenshot (of your code running the
QProcess
) shows a path which is simply incorrect. Whether you've changed that since screenshot I cannot say. -
@krist
Then you need to use something in your code which is actually the same as that, not what your screen shot has which is simply not the same!
Hint:/home/krist/Qt5.13.2/Examples/Qt-5.13.2/gui/build-analogclock-Desktop_Qt_5_13_2_GCC_64bit-Debug/analogclock
.
Which you seem to have had at one point, and then changed to something wrong.