I want to load the data from text file ..and i successfully did it by loading it in textbrowser....Now I want to load the specific characters into line edit whenever I encounter 0 in string of text file .....I succededd here but the program shows errror
Error message:::The application has requested the runtime to terminate in a unusual way
Please contact the application support team for more information
My Code::
void MainWindow::on_pushButton_clicked()
{
QString filename
= QFileDialog::getOpenFileName(this, tr
("wew"),
"",tr
("allfiles(*.txt)"));
{
//QString mm;
//char *ptr;
// QByteArray ba;
while (!in.atEnd())
{
line = in.readLine(0);//reads whole text file and loads it to Qstring line
// ba=line.toLatin1();
//line.fromLatin1(ba,-1);
ui->textBrowser->setText(line);
}
for(int i=0;i<=line.length();++i)
{
// ba=mm.toLatin1();
//*ptr=ba.data();
// if(line.at(i)==QChar('s'))
//{
//line.append("ssss");
//}
QChar ch
=line.
at(i
).
toAscii();
int chvalue=ch.toAscii();
if(chvalue==48)
{
ui->lineEdit->setText(ch);
}
}
file.close();
}
}
void MainWindow::on_pushButton_clicked()
{
QString filename = QFileDialog::getOpenFileName(this, tr("wew"),"",tr("allfiles(*.txt)"));
QFile file(filename);
if(file.open(QIODevice::ReadOnly | QIODevice::Text));
{
QTextStream in(&file);
//QString mm;
QString line;
//char *ptr;
// QByteArray ba;
while (!in.atEnd())
{
line = in.readLine(0);//reads whole text file and loads it to Qstring line
// ba=line.toLatin1();
//line.fromLatin1(ba,-1);
ui->textBrowser->setText(line);
}
for(int i=0;i<=line.length();++i)
{
// ba=mm.toLatin1();
//*ptr=ba.data();
// if(line.at(i)==QChar('s'))
//{
//line.append("ssss");
//}
QChar ch=line.at(i).toAscii();
int chvalue=ch.toAscii();
if(chvalue==48)
{
ui->lineEdit->setText(ch);
}
}
file.close();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks