hey in your code itself u can check the line number ...
Qt Code:
if(linenumber == 3) printf( "%3d: %s\n", linenumber, line.latin1() ); linenumber++;To copy to clipboard, switch view to plain text mode
hey in your code itself u can check the line number ...
Qt Code:
if(linenumber == 3) printf( "%3d: %s\n", linenumber, line.latin1() ); linenumber++;To copy to clipboard, switch view to plain text mode
"Behind every great fortune lies a crime" - Balzac
That line number input will be given from user in the QLineEdit then that line number contents should be read and put into a QString. how to do this.
Thanks & Regards
Sandeep G.R.
QString linenumber;
int lineNo;
bool ok;
linenumber = lineEdit->text()
lineNo = linenumber.toInt(&ok, 10);
then the condition
"Behind every great fortune lies a crime" - Balzac
I implemented your logic but i am getting different values means its reading the last line of the text file and here is my code
void DatumForm::readfile()
{
datumnolineEdit->setFocus();
resulttemp = datumnolineEdit->text();
decimals_mm_datum = 3;
QStringList lines;
QString resulttemp;
QFile file( "datum.txt" );
if ( file.open( IO_ReadWrite ) ) {
QTextStream stream( &file );
QString line;
while ( !stream.atEnd() ) {
line = stream.readLine( );
linenumber = resulttemp.toInt(&ok, 10);
if ( linenumber == resulttemp )
{
printf( "%3d: %s\n", linenumber, line.latin1() );
linenumber++;
lines +=line;
}
resulttemp = line;
qDebug("Read a particular Datum");
printf( "%3d: %s\n", linenumber, resulttemp.latin1() );
datumlines = QStringList::split(",", resulttemp);
qDebug ( "Datum number : %d",Datumno_Val);
Xdatum_Val = datumlines[0].toDouble();
xdatcountlineEdit->setText(QString::number( Xdatum_Val, 'f', decimals_mm_datum) );
qDebug ( "Xdatum_Val : %4.3lf",Xdatum_Val);
Ydatum_Val = datumlines[1].toDouble();
ydatcountlineEdit->setText(QString::number( Ydatum_Val, 'f', decimals_mm_datum) );
qDebug ( "Ydatum_Val : %4.3lf",Ydatum_Val);
Zdatum_Val = datumlines[2].toDouble();
zdatcountlineEdit->setText(QString::number( Zdatum_Val, 'f', decimals_mm_datum) );
qDebug ( "Zdatum_Val : %4.3lf",Zdatum_Val);
}
file.close();
}
}
how to proceed further.
Last edited by grsandeep85; 30th July 2009 at 13:19.
Thanks & Regards
Sandeep G.R.
please use [CODE] tag
Qt Code:
void DatumForm::readfile() { QString resulttemp; int count = 0; bool ok; resulttemp = datumnolineEdit->text(); int lineNo = resulttemp.toInt(&ok, 10); if ( file.open( IO_ReadWrite ) ) { while ( !stream.atEnd() ) { count += 1; line = stream.readLine( ); if(lineNo == count) printf( "%3d: %s\n", count, line.latin1() ); } file.close(); }To copy to clipboard, switch view to plain text mode
Last edited by wagmare; 30th July 2009 at 13:27. Reason: change in int lineNo
"Behind every great fortune lies a crime" - Balzac
Thanks its working fine but during the startup its displaying the last linenumber content how to overcome this issue. the contents are printed in the console terminal and also i need to split the read line and display in the line edits.
Last edited by grsandeep85; 31st July 2009 at 08:28.
Thanks & Regards
Sandeep G.R.
I solved the problem and my code is here...
QString resulttemp;
QString line;
int count = -1;
bool ok;
resulttemp = datumnolineEdit->text();
int linenumber = resulttemp.toInt(&ok, 10);
QFile file( "datum.txt" );
if ( file.open( IO_ReadWrite ) ) {
QTextStream stream( &file );
while ( !stream.atEnd() ) {
count += 1;
line = stream.readLine( );
if(linenumber == count){
resulttemp = line;
datumlines = QStringList::split(",", resulttemp);
qDebug ( "Datum number : %d",Datumno_Val);
Xdatum_Val = datumlines[0].toDouble();
xdatcountlineEdit->setText(QString::number( Xdatum_Val, 'f', decimals_mm_datum) );
qDebug ( "Xdatum_Val : %4.3lf",Xdatum_Val);
Ydatum_Val = datumlines[1].toDouble();
ydatcountlineEdit->setText(QString::number( Ydatum_Val, 'f', decimals_mm_datum) );
qDebug ( "Ydatum_Val : %4.3lf",Ydatum_Val);
Zdatum_Val = datumlines[2].toDouble();
zdatcountlineEdit->setText(QString::number( Zdatum_Val, 'f', decimals_mm_datum) );
qDebug ( "Zdatum_Val : %4.3lf",Zdatum_Val);
qDebug ("Result values of a corresponding datum points");
printf( "%3d: %s\n", count, line.latin1() );
}
}
file.close();
}
Thanks & Regards
Sandeep G.R.
Bookmarks