{
setupUi(this);
okButton->setEnabled(false); // disable OK button
connect(inputFileBrowseButton,SIGNAL(clicked()),this,SLOT(inputFileNameBrowse()));
connect(outputFileBrowseButton,SIGNAL(clicked()),this,SLOT(outputFileDirectoryBrowse()));
connect(aboutButton,SIGNAL(clicked()),this,SLOT(aboutinfo()));
connect(okButton,SIGNAL(clicked()),this,SLOT(processFile()));
}
void DataConvertor::processFile()
{
QString fileName
=inputFileNameComboBox
->currentText
();
if(fileName.isEmpty())
{
QMessageBox::information(this,tr
("Data Convertor"),tr
("Not such a file, Please reselect a file."),
QMessageBox::Ok);
}
else
{
//Open read file.
{
QMessageBox::information(this,tr
("Data Convertor"),tr
("Cann't read file %1:\n%2.").
arg(file.
fileName()).
arg(file.
errorString()),
QMessageBox::Cancel);
return;
}
//Open write directory.
QString outDirName
=outputFileDirectoryComboBox
->currentText
();
///
//if the directory is not existed, create one.
if(!outDir.exists())
{
outDir.mkpath(outDirName);
}
// form outfile name.
// setup QProgressDailog
progressDialog.setCancelButtonText(tr("&Cancel"));
progressDialog.setRange(0, file.size());
progressDialog.setWindowTitle(tr("Loading..."));
while(file.pos()<file.size())
{
progressDialog.setValue(file.pos());
progressDialog.setLabelText(tr("Searching file number %1 of %2...")
.arg(file.pos()).arg(file.size()));
qApp->processEvents();
if (progressDialog.wasCanceled())
break;
line=in.readLine();
out<<line;
}
}
}
DataConvertor::DataConvertor(QWidget *parent):QDialog(parent)
{
setupUi(this);
okButton->setEnabled(false); // disable OK button
connect(inputFileBrowseButton,SIGNAL(clicked()),this,SLOT(inputFileNameBrowse()));
connect(outputFileBrowseButton,SIGNAL(clicked()),this,SLOT(outputFileDirectoryBrowse()));
connect(aboutButton,SIGNAL(clicked()),this,SLOT(aboutinfo()));
connect(okButton,SIGNAL(clicked()),this,SLOT(processFile()));
}
void DataConvertor::processFile()
{
QString fileName=inputFileNameComboBox->currentText();
if(fileName.isEmpty())
{
QMessageBox::information(this,tr("Data Convertor"),tr("Not such a file, Please reselect a file."),QMessageBox::Ok);
}
else
{
QFile file(fileName);
//Open read file.
if(!file.open(QIODevice::ReadOnly))
{
QMessageBox::information(this,tr("Data Convertor"),tr("Cann't read file %1:\n%2.").arg(file.fileName()).arg(file.errorString()),QMessageBox::Cancel);
return;
}
//Open write directory.
QString outDirName=outputFileDirectoryComboBox->currentText();
QDir outDir(outDirName);
///
//if the directory is not existed, create one.
if(!outDir.exists())
{
outDir.mkpath(outDirName);
}
QTextStream in(&file);
// form outfile name.
QString path=outDirName+QDir::separator()+"abc.txt";
QFile outFile(path);
QTextStream out(&outFile);
// setup QProgressDailog
QProgressDialog progressDialog(this);
progressDialog.setCancelButtonText(tr("&Cancel"));
progressDialog.setRange(0, file.size());
progressDialog.setWindowTitle(tr("Loading..."));
QString line;
while(file.pos()<file.size())
{
progressDialog.setValue(file.pos());
progressDialog.setLabelText(tr("Searching file number %1 of %2...")
.arg(file.pos()).arg(file.size()));
qApp->processEvents();
if (progressDialog.wasCanceled())
break;
line=in.readLine();
out<<line;
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks