PDA

View Full Version : Assert problem in line edit



grsandeep85
27th July 2009, 06:44
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

spirit
27th July 2009, 06:56
maybe lines is empty?
try to add this line in your code


void DatumForm::init()
{
...
QStringList lines = QStringList::split( FIELD_SEP, resulttemp );
if (lines.isEmpty())
return;
...
}

nish
27th July 2009, 07:06
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.

grsandeep85
27th July 2009, 07:33
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.

spirit
27th July 2009, 07:36
does that mean that you don't get any assert messages after using that code?

grsandeep85
27th July 2009, 07:53
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.

spirit
27th July 2009, 07:58
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.

grsandeep85
27th July 2009, 08:02
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

spirit
27th July 2009, 08:06
you said that you have not get any assertation messages, but in your last post there are. :confused:
can you attach compilable project?

grsandeep85
27th July 2009, 08:13
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.

nish
27th July 2009, 08:19
in your readline() try to replace

resulttemp = result;

with

resulttemp+ = FIELD_SEP+result;

spirit
27th July 2009, 08:30
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


void DatumForm::init()
{
...
QStringList lines = QStringList::split( FIELD_SEP, resulttemp );
qDebug() << resulttemp;
qDebug() << lines;
...
}

and show us what will you see in console.

grsandeep85
27th July 2009, 09:25
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 #

spirit
27th July 2009, 09:28
ah, I've just noticed that you use Qt 3. ok.
as I see resulttemp contatins resulttemp=::::, that explains why lines is empty.

spirit
27th July 2009, 09:36
btw, I think you reg exp is not exaclty correct, try to use this one: \d+.

grsandeep85
27th July 2009, 10:43
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

spirit
27th July 2009, 10:52
did you look at Qt Assistant, there is an example in QRegExp::search (http://doc.qtsoftware.com/3.3/qregexp.html#search)?


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

grsandeep85
27th July 2009, 11:18
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.

spirit
27th July 2009, 14:41
if it doesn't work then it is not correct. :)

grsandeep85
28th July 2009, 05:30
Then how to proceed further is there any other method to perform this operation.