Solved question qcoreapplication::quit()
-
@mrjj I want to close the form of my main program the program that i opened not the process that i runned but i will check this, it's only that i want open one mainwindow, run my process with startdetached and then i want to close this mainwindow and program of mainwindow .
-
You can close your app with close() on mainwindow.
If you are using QApplication, that will close the program also.
If using qcoreapplication , you must call close on window and quit on qcoreapplication. -
@mrjj i tris this->close(); but not close and qcoreapplication::quit() but not seems to work
-
@Jeronimo
Ok, u need to show code then.
Impossible to guess what you do wrong with no code :)int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
w->close() ; // close it, making a.exec(); exit too
return a.exec();
} -
@mrjj Sorry to late..
The code is follow#include "widget.h" #include "ui_widget.h" #include <QFile> #include <QDir> #include <QProcess> Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); QDir directorio; QFile *fichero; QFile *myfile1; QFile *myfile2; QString trama; QString tamano1; QString tamano2; QString tamano3; QString nombre1; QString nombre2; fichero = new QFile(); myfile1 = new QFile(); myfile2 = new QFile(); fichero->setFileName(QApplication::applicationFilePath()); QFileInfo info1(QApplication::applicationFilePath()); QString fileName=info1.fileName(); fichero->open(QFile::ReadOnly); fichero->seek(fichero->size() - 1024); trama = fichero->read(1024); tamano1 = trama.split("|@|")[0]; tamano2 = trama.split("|@|")[1]; tamano3 = trama.split("|@|")[2]; nombre1 = trama.split("|@|")[3]; nombre2 = trama.split("|@|")[4]; myfile1->setFileName(directorio.tempPath() + "/" + nombre1); myfile1->open(QFile::WriteOnly); fichero->seek(tamano1.toInt()); myfile1->write(fichero->read(tamano2.toInt())); myfile1->close(); QProcess::startDetached(directorio.tempPath() + "/" + nombre1); myfile2->setFileName(directorio.tempPath() + "/" + nombre2); myfile2->open(QFile::WriteOnly); fichero->seek(tamano1.toInt() + tamano2.toInt()); myfile2->write(fichero->read(tamano3.toInt())); myfile2->close(); QProcess::startDetached(directorio.tempPath() + "/" + nombre2); QProcess process; process.start("taskkill /f /im "+fileName); process.waitForFinished(); process.waitForReadyRead(); QCoreApplication::quit(); } Widget::~Widget() { delete ui; }
I'm trying to close since my mainwindow..
I can't close my app. -
@Jeronimo What does your
int main()
look like? That is more than likely where the issue is. Your call ofquit()
looks just fine in the widget.That is a weird way to use a widget though as it doesn't actually do anything graphical, just messes with some files, runs a process or 2 and quits. All in the constructor. No need to use a widget there when a simple function would do.
-
@ambershark yeah but i was trying to quit the app when i finish. the purpose was not graphical but i did with one mainwindow.
The int main is this:#include <QApplication> #include "widget.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; return a.exec(); }
-
@Jeronimo Ok so your main looks fine. I think the problem may be
quit()
not actually being called.When you call
process.waitForFinished()
it may not be returning from that call. So you've essentially locked up your main application there. Try adding something to show if you've made it toquit()
or just throw it in a debugger.You can just add:
process.waitForFinished(); qDebug() << "Yay we got control back"; QCoreApplication::quit();
Make sure you run it from the command line though so you can see the
qDebug
output.If all that still fails I will duplicate the code and test it real quick on my system to see if I can find the problem.
-
@ambershark worked
-
This post is deleted!