Assert problem in line edit
Hi All ,
have a text file in the format
#n X Y Z
0 123 456 789
1 321 654 987
2 345 243 809
......
.....
...... and so on
now i am reading the contents of the datum number(n) and X Y Z values using QRegExp but if try to read i am getting ASSERT problem please help us here is my code and error msg
void DatumForm::readfile()
{
QString result;
QFile file( "datum.txt" );
if ( file.open( IO_ReadOnly ) ) {
QTextStream stream( &file );
QString line;
int linenumber = 0;
while ( !stream.atEnd() ) {
line = stream.readLine();
QRegExp rx ( "^\\d\\d?$" );
rx.search ( "Datumno_Val" );
result = rx.cap ( 0 );
resulttemp = result;
printf( "%3d: %s\n", linenumber++, line.latin1() );
//lines += line;
}
file.close();
}
}
void DatumForm::init()
{
Datumno_Val = DatumVal;
datumnolineEdit->setFocus();
decimals_mm_datum = 3;
readfile();
QStringList lines = QStringList::split( FIELD_SEP, resulttemp );
Datumno_Val = lines[0].toInt();
qDebug ( "Datum number : %d",Datumno_Val);
Xdatum_Val = lines[1].toDouble();
xdatcountlineEdit->setText(QString::number( Xdatum_Val, 'f', decimals_mm_datum) );
qDebug ( "Xdatum_Val : %4.3lf",Xdatum_Val);
Ydatum_Val = lines[1].toDouble();
qDebug ( "Ydatum_Val : %4.3lf",Ydatum_Val);
Zdatum_Val = lines[1].toDouble();
qDebug ( "Zdatum_Val : %4.3lf",Zdatum_Val);
}
#######Error Msg##########
Key Press Event:: DATUM
0: 0:123.000:456.000:789.000
Datum number : 0
ASSERT: "i <= nodes" in /usr/lib/qt3/include/qvaluelist.h (373)
Xdatum_Val : 0.000
ASSERT: "i <= nodes" in /usr/lib/qt3/include/qvaluelist.h (373)
Ydatum_Val : 0.000
ASSERT: "i <= nodes" in /usr/lib/qt3/include/qvaluelist.h (373)
Zdatum_Val : 0.000
Re: Assert problem in line edit
maybe lines is empty?
try to add this line in your code
Code:
void DatumForm::init()
{
...
if (lines.isEmpty())
return;
...
}
Re: Assert problem in line edit
cant you see what message you get on assert failure? it must say index out of range or something.. from there you can get a hint... and plz use the [code] tags.
Re: Assert problem in line edit
Hi Spirit,
I tried this in my code
if (lines.isEmpty())
return;
but i am not getting any errors and the thing is i am not able to read the Datum number line values please help me.
Re: Assert problem in line edit
does that mean that you don't get any assert messages after using that code?
Re: Assert problem in line edit
Yes.. but my intension is to read the Datum number(n) line values by using QRegExp and then split that line, get the X Y Z values and store it in another variables. and my code is correct or any modifications has to be done.
Re: Assert problem in line edit
as I said your list lines is empty (QList::isEmpty returns true),
that means that parse (DatumForm::readfile) method works wrong, because (probably) resulttemp also is empty.
Re: Assert problem in line edit
But i am able to read the file contents in the console terminal as below
Datum number : 0
Xdatum_Val : 0.000
Ydatum_Val : 0.000
Zdatum_Val : 0.000
0: 0:123.000:456.000:789.000
1: 1:321.000:654.000:987.000
2: 2:123.000:456.000:789.000
Re: Assert problem in line edit
you said that you have not get any assertation messages, but in your last post there are. :confused:
can you attach compilable project?
Re: Assert problem in line edit
but its size is around 2.8Mb project files how to upload this in the forum. Also if i use
if (lines.isEmpty())
return;
i wont get assert message.
Re: Assert problem in line edit
in your readline() try to replace
resulttemp = result;
with
resulttemp+ = FIELD_SEP+result;
Re: Assert problem in line edit
Quote:
Originally Posted by
grsandeep85
but its size is around 2.8Mb project files how to upload this in the forum. Also if i use
if (lines.isEmpty())
return;
i wont get assert message.
ok, the try to do next
Code:
void DatumForm::init()
{
...
qDebug() << resulttemp;
qDebug() << lines;
...
}
and show us what will you see in console.
Re: Assert problem in line edit
if i try to use
QStringList lines = QStringList::split( FIELD_SEP, resulttemp );
qDebug() << resulttemp;
qDebug() << lines;
then i will get error message as
/usr/lib/qt3/include/qglobal.h: In member function ‘void DatumForm::init()’:
/usr/lib/qt3/include/qglobal.h:975: error: too few arguments to function ‘void qDebug(const char*, ...)’
datumform.ui.h:55: error: at this point in file
/usr/lib/qt3/include/qglobal.h:975: error: too few arguments to function ‘void qDebug(const char*, ...)’
datumform.ui.h:56: error: at this point in file
make: *** [datumform.o] Error 1
then i used
void DatumForm::init()
{
readfile();
QStringList lines = QStringList::split( FIELD_SEP, resulttemp );
// qDebug() << resulttemp;
// qDebug() << lines;
printf( "resulttemp=%s\n", resulttemp.latin1() );
if (lines.isEmpty())
return;
Datumno_Val = lines[0].toInt();
Xdatum_Val = lines[1].toDouble();
Ydatum_Val = lines[2].toDouble();
Zdatum_Val = lines[3].toDouble();
}
to print resulttemp and message displayed in the console as
Key Press Event:DATUM
0: 0:123.000:456.000:789.000
1: 1:321.000:654.000:987.000
2: 2:963.000:852.000:741.000
3: 3:357.000:214.000:698.000
resulttemp=::::
drass:/home/dro_changed/dro_som1 #
Re: Assert problem in line edit
ah, I've just noticed that you use Qt 3. ok.
as I see resulttemp contatins resulttemp=::::, that explains why lines is empty.
Re: Assert problem in line edit
btw, I think you reg exp is not exaclty correct, try to use this one: \d+.
Re: Assert problem in line edit
I used QRegExp rx ( "(\\d+)" );
even after that also i m get the message as
Key Press EventATUM
0: 0:123.000:456.000:789.000
1: 1:321.000:654.000:987.000
2: 2:963.000:852.000:741.000
3: 3:357.000:214.000:698.000
resulttemp=::::
Please help me how to proceed further
Re: Assert problem in line edit
did you look at Qt Assistant, there is an example in QRegExp::search?
Code:
QString str
= "offsets: 1.23 .50 71.00 6.00";
QRegExp rx
( "\\d*\\.\\d+" );
// primitive floating point matching int count = 0;
int pos = 0;
while ( (pos = rx.search(str, pos)) != -1 ) {
count++;
pos += rx.matchedLength();
}
// pos will be 9, 14, 18 and finally 24; count will end up as 4
Re: Assert problem in line edit
Here i am not using fixed string,, even i went through the examples also.
The format of the file is as below and user will be writing some more values into the file maximum is 99 points and simultaneously user need to read the values.
Datum X Y Z
0 123 456 789
1 321 654 987
2 345 243 809
......
.....
...... and so on
now i need to search for Datum number i.e., first column only then i need to read the corresponding line split the Datum, X, Y, Z values and store in 3 different variables.
QRegExp rx ( "(\\d+)" );
rx.search ( "Datumno_Val" );
is my code is correct or not.
Re: Assert problem in line edit
if it doesn't work then it is not correct. :)
Re: Assert problem in line edit
Then how to proceed further is there any other method to perform this operation.