Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. question qcoreapplication::quit()
Forum Updated to NodeBB v4.3 + New Features

question qcoreapplication::quit()

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 5.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrjjM mrjj

    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?

    J Offline
    J Offline
    Jeronimo
    wrote on last edited by
    #4

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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #5

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

      J 1 Reply Last reply
      1
      • mrjjM mrjj

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

        J Offline
        J Offline
        Jeronimo
        wrote on last edited by
        #6

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

        mrjjM 1 Reply Last reply
        0
        • J Jeronimo

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

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #7

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

          J 1 Reply Last reply
          1
          • mrjjM mrjj

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

            J Offline
            J Offline
            Jeronimo
            wrote on last edited by
            #8

            @mrjj i tris this->close(); but not close and qcoreapplication::quit() but not seems to work

            mrjjM 1 Reply Last reply
            0
            • J Jeronimo

              @mrjj i tris this->close(); but not close and qcoreapplication::quit() but not seems to work

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #9

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

              J 1 Reply Last reply
              2
              • mrjjM mrjj

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

                J Offline
                J Offline
                Jeronimo
                wrote on last edited by Jeronimo
                #10

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

                A 1 Reply Last reply
                0
                • J Jeronimo

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

                  A Offline
                  A Offline
                  ambershark
                  wrote on last edited by
                  #11

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

                  My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                  J 1 Reply Last reply
                  3
                  • A ambershark

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

                    J Offline
                    J Offline
                    Jeronimo
                    wrote on last edited by Jeronimo
                    #12

                    @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();
                    }
                    
                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      ambershark
                      wrote on last edited by
                      #13

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

                      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                      J 1 Reply Last reply
                      2
                      • A ambershark

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

                        J Offline
                        J Offline
                        Jeronimo
                        wrote on last edited by
                        #14

                        @ambershark worked

                        1 Reply Last reply
                        1
                        • J Offline
                          J Offline
                          Jeronimo
                          wrote on last edited by
                          #15
                          This post is deleted!
                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved