doubt regarding QT ( VERYYYY URGENT!!!!)

E

edu.mvk

Hi,

i'm trying to use QFile in my program and trying to read a line from
that file as :


Q_ULONG maxLen=60;
QFile mapFile("/users/a22596/mapping");
if( !mapFile.open(IO_ReadOnly) )
exit(0);
if( !mapFile.exists() )
exit(0);


the above code is working fine....


but when i tried reading a line as below :


mapFile.readLine(p_qcop_channel_pt,maxLen)


a Segmentation Fault is occurring..


Please help me how to use this "readLine" function.
 
M

mlimber

edu.mvk said:
Hi,

i'm trying to use QFile in my program and trying to read a line from
that file as :


Q_ULONG maxLen=60;
QFile mapFile("/users/a22596/mapping");
if( !mapFile.open(IO_ReadOnly) )
exit(0);
if( !mapFile.exists() )
exit(0);


the above code is working fine....


but when i tried reading a line as below :


mapFile.readLine(p_qcop_channel_pt,maxLen)


a Segmentation Fault is occurring..


Please help me how to use this "readLine" function.

You'll need to post in a more appropriate forum. This is a newsgroup to
discuss the *standard* C++ language, not arbitrary third-party
libraries. Please see this FAQ for what is on-topic here and for some
ideas of where else you might ask:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Cheers! --M
 
H

Howard

edu.mvk said:
Hi,

i'm trying to use QFile in my program and trying to read a line from
that file as :


Q_ULONG maxLen=60;
QFile mapFile("/users/a22596/mapping");
if( !mapFile.open(IO_ReadOnly) )
exit(0);
if( !mapFile.exists() )
exit(0);


the above code is working fine....


but when i tried reading a line as below :


mapFile.readLine(p_qcop_channel_pt,maxLen)


a Segmentation Fault is occurring..


Please help me how to use this "readLine" function.

This isn't the correct forum to discuss how to use third-party software.

BUT!... how is p_qcop_channel_pt defined? Perhaps you're passing an
uninitialized pointer?

If the parameter for readLine is a char*, and the function is supposed to
fill a buffer pointed to by that char*, then you may need to be sure that
you've allocated space in the buffer. (Check the documentation for readLine
to be sure.)

Here are two examples of ways to initialize and pass buffers for calls like
this:

char p_qcop_channel_pt[maxLen+1]; // 1 extra, for NULL-terminator, (if
needed)
mapFile.readLine(p_qcop_channel_pt,maxLen);

or

char* p_qcop_channel_pt = new char[maxLen+1];
mapFile.readLine(p_qcop_channel_pt,maxLen);
....later...
delete[] p_qcop_channel_pt;


In the future, it would help if you post your variable declarations (as well
as the function protototype in cases like this, where an external function
is involved). Then we can easily tell if the problem is related to C++ or
to some third-party software issues.

-Howard
 
B

Berny Cantos

Hi edu,
but when i tried reading a line as below :
mapFile.readLine(p_qcop_channel_pt,maxLen)
a Segmentation Fault is occurring..

Refer to QFile member functions in Qt website. It's website has a
perfectly structured developer-zone where they explain every Qt class
deeply. Visit http://www.trolltech.com/

QFile::readLine syntax has any form of the following:
Q_LONG QFile::readLine( char * p, Q_ULONG maxlen );
Q_LONG QFile::readLine( QString& s, Q_ULONG maxlen );

As far as 'p_qcop_channel_pt' is a QString, there should be no problem.
Instead, I think that your variable is storing a simple pointer to
char, pointing anywhere.
If you _must_ use a pointer, be sure you alloc enough memory to store,
at least, maxlen + 1 chars on it.

--- Hoping this helps you ---
--- Bye! ---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top