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. [SOLVED] Process not exiting
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Process not exiting

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 912 Views 1 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.
  • B Offline
    B Offline
    bl00pbl00p
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bl00pbl00p
        wrote on last edited by
        #3

        I works ! thank you so much :)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bl00pbl00p
            wrote on last edited by
            #5

            Thanks I was searching the solved button :)

            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