Dialog:
ialog(QWidget *parent)
: QDialog(parent)
{
inLabel = new QLabel(tr("Input: "));
inEdit = new QLineEdit(tr("/home/sp75/sp24.txt"));
outLabel = new QLabel("Output:");
outEdit = new QLineEdit("/home/sp75/sp24_mo1.txt");
QHBoxLayout *inLayout = new QHBoxLayout;
inLayout->addWidget(inLabel);
inLayout->addWidget(inEdit);
QHBoxLayout *outLayout = new QHBoxLayout;
outLayout->addWidget(reiheLabel);
outLayout->addWidget(reiheEdit);
showText = new QTextEdit;
QHBoxLayout *btnLayout = new QHBoxLayout;
untenLayout->addWidget(okButton);
untenLayout->addStretch();
untenLayout->addWidget(endButton);
connect(okButton, SIGNAL(clicked()), this, SLOT(loadTextFile()));
connect(endButton, SIGNAL(clicked()), this, SLOT(close()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(inLayout);
mainLayout->addLayout(outLayout);
mainLayout->addWidget(showText);
mainLayout->addLayout(btnLayout);
setLayout(mainLayout);
}
void Dialog::loadTextFile()
{
QString rowTxt, txtFileStr;
txtFileStr =inEdit->text();
QFile inputTxtFile(txtFileStr);
if(!inputTxtFile.open(QIODevice::ReadOnly))
qFatal( "Could not open the file" );
QTextStream inTxt(&inputTxtFile);
rowTxt.append(inTxt.readAll());
inputTxtFile.close();
QStringList lineTxt = rowTxt.split('\n');
QString outStr;
outStr = outEdit->text();
QFile outFile(outStr);
if(!outFile.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream out(&outFile);
QString oneLine, word, temp;
for (int i = 0; i < lineTxt.size(); ++i){
lineZeile = lineTxt.at(i);
if (!lineZeile.isEmpty()){
oneLine = lineTxt.at(i);
QStringList word = oneLine.split('#');
for (int i = 1; i < word.size(); ++i)
{
temp =word.at(i);
if(!temp.isEmpty())
output += temp+ '\n';
}
}
}
showText->append(output);
showText->setUndoRedoEnabled(false);
showText->setUndoRedoEnabled(true);
out << output;
}
Bookmarks