[SOLVED] Process not exiting



  • Hello, I am trying to make a program to rename some files but after the renaming is done the program does not exit. Please help me.
    Here is the code:
    @#include <QApplication>
    #include <QFileDialog>
    #include <QDir>
    #include <iostream>
    #include <QDebug>

    class Tester : public QWidget
    {
    public:
    void openDir()
    {
    QString dirstring = QFileDialog::getExistingDirectory(this,tr("Select a Directory"),QDir::currentPath());
    QDir dir (dirstring);
    dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
    // dir.setSorting(QDir::Size | QDir::Reversed);
    QFileInfoList list = dir.entryInfoList();
    for (int i = 0; i < list.size(); ++i) {
    QFileInfo fInfo = list.at(i);
    QString fPath = fInfo.absoluteFilePath();
    QFile file (fPath);
    QString fPathwhitoutfilename = fInfo.absolutePath();
    qDebug() << fPath;
    QString cc = QString::number(i);
    file.rename(fPathwhitoutfilename+"/"+cc+".jpg");
    QApplication::quit();
    }
    }
    };

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    Tester t;
    t.openDir();
    return app.exec();
    }
    @



  • You call QApplication::quit() in the loop. So if it would work your app would exit after first file is processed.

    It does not exit, because you call QApplication::quit() before application enters the main event loop. The main event loop starts with app.exec().

    I would suggest to delete QApplication::quit() line in openDir() and don't call app.exec() at return. Just return 0.



  • I works ! thank you so much :)



  • Glad it works.
    Could you pre-prepend "[SOLVED]" to the title of your original post please.



  • Thanks I was searching the solved button :)


Log in to reply
 

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