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.


  • Qt Champions 2016

    Hi
    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.


  • Qt Champions 2016

    You might be able to kill it with
    Myprocess->close();
    http://doc.qt.io/qt-5/qprocess.html
    or even
    Myprocess->kill();



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


  • Qt Champions 2016

    @Jeronimo

    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


  • Qt Champions 2016

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


  • Moderators

    @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();
    }
    

  • Moderators

    @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:

    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!

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.