⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

question qcoreapplication::quit()

  • Hi i did one program to start my external application's with qprocess::startDetached but when i start these applications i can't to close the actual with qcoreapplication::quit() i tried with exit but nothing someone know why?

  • i'm using one form but i want to close this.

  • Lifetime Qt Champion

    Are you try to close the external app?
    Also in a normal GUI program its not qcoreapplication, but QApplication.

    are you calling qcoreapplication::quit() inside the external app?

  • @mrjj i have one app that call with qprocess startDetached different app's and when i finished to call to show my other application's i am trying to close this. So i have one main form with qt than call two different app's and then close. But anyways i can't' close and the application still is live i tried with taskkill process but show me one error sometimes idk why. Anyways too with qcoreapplication and quit but nothing.

  • Lifetime Qt Champion

    You might be able to kill it with
    or even

  • @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 .

  • Lifetime Qt Champion


    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

  • Lifetime Qt Champion

    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->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) :
        ui(new Ui::Widget)
        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();
    	QFileInfo info1(QApplication::applicationFilePath());
    	QString fileName=info1.fileName();
        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);
        QProcess::startDetached(directorio.tempPath() + "/" + nombre1);
        myfile2->setFileName(directorio.tempPath() + "/" + nombre2);
        fichero->seek(tamano1.toInt() + tamano2.toInt());
        QProcess::startDetached(directorio.tempPath() + "/" + nombre2);
    	QProcess process;
    	process.start("taskkill /f /im "+fileName);
        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 of quit() 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 to quit() or just throw it in a debugger.

    You can just add:

    qDebug() << "Yay we got control back";

    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!

Log in to reply