No problem here is the full chunk of code that I am trying to execute...
void MainWindow::open()
{
if(okToContinue())
{
QString fileName
= QFileDialog::getOpenFileName(this, tr
("Open file.tar.gz file or A.csv"),
".", tr
("Data Files (*.tar.gz *.tar *.csv)"));
if(!fileName.isEmpty() && fileName.contains("tar.gz"))
{
arguments << "-ext2here" << fileName;
unarchive.start("peazip", arguments);
if(unarchive.waitForFinished())
{
unarchive.close();
fileName.remove(".gz");
arguments.clear();
arguments << "-ext2here" << fileName;
}
untar.start("peazip", arguments);
if(untar.waitForFinished())
{
untar.close();
fileName.remove("file.tar");
while(!dir.cd("tmp"))
cout << "Waiting for tmp to be created\n";
}
if(dir.cd("tmp"))
{
cout << "tmp has been created and found\n";
if(dir.cd("file"))
{
cout << "file has been created and found\n";
cout << "Absolute path: " << dir.absolutePath().toStdString() << endl;
// says 11 when it should be 40...
while(dir.count() < 40)
{
cout << "Number of files: " << dir.count() << endl;
dir.refresh();
}
QFile file(dir.
filePath("A.csv"));
if(file.exists())
{
cout << "A.csv has been created and found\n";
cout << "Filename is: " << file.fileName().toStdString() << endl;
loadFile(file.fileName());
}
else
{
cout << "Cannot find A.csv\n";
}
}
}
}
else if(!fileName.isEmpty() && fileName.contains("A.csv"))
{
loadFile(fileName);
}
}
}
void MainWindow::open()
{
if(okToContinue())
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open file.tar.gz file or A.csv"), ".", tr("Data Files (*.tar.gz *.tar *.csv)"));
if(!fileName.isEmpty() && fileName.contains("tar.gz"))
{
QProcess unarchive(this);
QStringList arguments;
arguments << "-ext2here" << fileName;
unarchive.start("peazip", arguments);
if(unarchive.waitForFinished())
{
unarchive.close();
fileName.remove(".gz");
arguments.clear();
arguments << "-ext2here" << fileName;
}
QProcess untar(this);
untar.start("peazip", arguments);
if(untar.waitForFinished())
{
untar.close();
fileName.remove("file.tar");
QDir dir(fileName);
while(!dir.cd("tmp"))
cout << "Waiting for tmp to be created\n";
}
QDir dir(fileName);
if(dir.cd("tmp"))
{
cout << "tmp has been created and found\n";
if(dir.cd("file"))
{
cout << "file has been created and found\n";
cout << "Absolute path: " << dir.absolutePath().toStdString() << endl;
// says 11 when it should be 40...
while(dir.count() < 40)
{
cout << "Number of files: " << dir.count() << endl;
dir.refresh();
}
QFile file(dir.filePath("A.csv"));
if(file.exists())
{
cout << "A.csv has been created and found\n";
cout << "Filename is: " << file.fileName().toStdString() << endl;
loadFile(file.fileName());
}
else
{
cout << "Cannot find A.csv\n";
}
}
}
}
else if(!fileName.isEmpty() && fileName.contains("A.csv"))
{
loadFile(fileName);
}
}
}
To copy to clipboard, switch view to plain text mode
That is my 'hack' way of doing it right now. This is me trying to figure out how QFileSystemWatcher works in order to make it work without the nasty hacks.
void MainWindow::open()
{
if(okToContinue())
{
QString fileName
= QFileDialog::getOpenFileName(this, tr
("Open file.tar.gz file or A.csv"),
".", tr
("Data Files (*.tar.gz *.tar *.csv)"));
if(!fileName.isEmpty() && fileName.contains("tar.gz"))
{
arguments << "-ext2here" << fileName;
unarchive.start("peazip", arguments);
if(unarchive.waitForFinished())
{
unarchive.close();
fileName.remove(".gz");
arguments.clear();
arguments << "-ext2here" << fileName;
}
untar.start("peazip", arguments);
if(untar.waitForFinished())
{
untar.close();
fileName.remove("file.tar");
}
QFileSystem watcher;
watcher.addPath(fileName);
connect(&watcher,
SIGNAL(directoryChanged
(String
),
this,
SLOT(directoryModified
(QString));
}
}
void MainWindow::directoryModified(const QString& path)
{
QMessageBox::information(this,
"Directory Modified",
"Your Directory is modified");
// not sure what I am going to do yet...
}
void MainWindow::open()
{
if(okToContinue())
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open file.tar.gz file or A.csv"), ".", tr("Data Files (*.tar.gz *.tar *.csv)"));
if(!fileName.isEmpty() && fileName.contains("tar.gz"))
{
QProcess unarchive(this);
QStringList arguments;
arguments << "-ext2here" << fileName;
unarchive.start("peazip", arguments);
if(unarchive.waitForFinished())
{
unarchive.close();
fileName.remove(".gz");
arguments.clear();
arguments << "-ext2here" << fileName;
}
QProcess untar(this);
untar.start("peazip", arguments);
if(untar.waitForFinished())
{
untar.close();
fileName.remove("file.tar");
}
QFileSystem watcher;
watcher.addPath(fileName);
connect(&watcher, SIGNAL(directoryChanged(String), this, SLOT(directoryModified(QString));
}
}
void MainWindow::directoryModified(const QString& path)
{
QMessageBox::information(this,"Directory Modified", "Your Directory is modified");
// not sure what I am going to do yet...
}
To copy to clipboard, switch view to plain text mode
When I run the 'correct' way of doing things I never see the information box pop up... So I am assuming I am somehow not using QFileSystemWatcher class correctly. Any help is greatly appreciated.
Bookmarks