PDA

View Full Version : How to transfer file through serial communication



shamik
17th May 2007, 09:34
hii friends,

i am using Qt3 which comes bydefault with FC-6 installation.
i want to transfer files like zip, pdf, jpeg etc through serial communication (i.e. using com port)

can anyone please tell me how can i achieve this?!?
if possible please provide me with a sample code.

wysota
17th May 2007, 11:36
Please start by searching the forum.

shamik
22nd May 2007, 08:01
i've downloaded the QExtSerialPort1.1 from the net

in this when i go to the /example/ folder and type "make" to compile everything
it gives following error :

make
make: Warning: File `Makefile' has modification time 2.3e+08 s in the
future
g++ -c -pipe -Wall -W -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
-fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32
-march=i386 -mtune=generic -fasynchronous-unwind-tables -D_REENTRANT
-D_TTY_POSIX_ -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED
-I/usr/lib/qt-3.3/mkspecs/default -I. -I../.. -I/usr/lib/qt-3.3/include
-Iuic/ -Imoc/ -o obj/main.o main.cpp
main.cpp:8:28: error: qextserialport.h: No such file or directory
In file included from main.cpp:12:
MessageWindow.h:12:25: error: qdockwidget.h: No such file or directory
MessageWindow.h:20: error: expected class-name before ‘{’ token
MessageWindow.h:20: warning: ‘class MessageWindow’ has virtual functions
but non-virtual destructor
make: *** [obj/main.o] Error 1

can anybody please help me with this ?

wysota
22nd May 2007, 09:15
main.cpp:8:28: error: qextserialport.h: No such file or directory
This seems obvious - the file is missing.


MessageWindow.h:12:25: error: qdockwidget.h: No such file or directory
This suggest you've downloaded the wrong release as QDockWidget is part of Qt4 and not Qt3.

freeskydiver
22nd May 2007, 10:18
...
MessageWindow.h:12:25: error: qdockwidget.h: No such file or directory
can anybody please help me with this ?

Look to the file. If it exists? Then look for QTDIR.

shamik
22nd May 2007, 10:45
u're right......i had downloaded a wrong package

now i have downloaded a correct one which works with Qt3. The make command has generated the libraries well.

but i dont know how to use this class and its functions.

all the function i found deals with byte transfer i.e. getch(), putch() etc.

but i want to transfer and recieve files like zip, pdf etc.

i cant find any such functions directly sending and recieving files...

can any1 plz suggest

wysota
22nd May 2007, 10:56
Use getch or putch in a loop.

shamik
22nd May 2007, 11:29
suppose its a zip file stored somewhere like /root/xp.zip

then how to use that getch() and putch() ??

wysota
22nd May 2007, 12:23
Oh come on.... What kind of a question is that?
Open the file, read characters and transmit them over the serial line. You'll probably need some protocol of communication to transfer the file length and file name. You can probably use QDataStream to ease your task.

high_flyer
22nd May 2007, 12:59
no need to use getch().
Just use readBytes() and you don't need a loop.
But the rest is the same as wysota said.

steg90
22nd May 2007, 13:42
Hi,

Plenty of serial comms classes on the web...

Personally, I use my own I wrote which is for windows, if it is for windows you want to use serial comms, just use api calls such as ::CreateFile, ::WriteFile etc...

Here is some code from my serial class, may help ( this is for Windows )?




template<class T=char, int nSize=100> class CSerialComms
{
public:
T& operator[]( int nIndex ) { return m_buf[nIndex]; }

CSerialComms& operator=( const CSerialComms& r )
{
memcpy( m_buf, r.m_buf, nSize );
m_cto = r.m_cto;
m_dcb = r.m_dcb;
m_hFile = r.m_hFile;
return *this;
}


inline int SetTimeouts( DWORD dwReadInterval = 1, DWORD dwReadTotalTimeout = 100, DWORD dwReadTotalTimeoutConstant = 1000, DWORD dwWriteTotalTimeout = 0, DWORD dwWriteTotalTimeoutConstant = 0 )
{
int nError = SUCCESS;
m_cto.ReadIntervalTimeout = dwReadInterval;
m_cto.ReadTotalTimeoutMultiplier = dwReadTotalTimeout;
m_cto.ReadTotalTimeoutConstant = dwReadTotalTimeoutConstant;
m_cto.WriteTotalTimeoutMultiplier = dwWriteTotalTimeout;
m_cto.WriteTotalTimeoutConstant = dwWriteTotalTimeoutConstant;
if( !::SetCommTimeouts( m_hFile, &m_cto) )
{
nError = GetLastError();
}
return nError;
}

inline int OpenPort( LPCTSTR szPort = "COM1" )
{
int nError = SUCCESS;
m_hFile = ::CreateFile( szPort, GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0, NULL);
if( m_hFile == INVALID_HANDLE_VALUE )
{
nError = GetLastError();
}
return nError;
}

inline int SetCommsDevice( DWORD dwBaud = 57600, BYTE iParity = NOPARITY, BYTE iStopBits = ONESTOPBIT, BYTE iByteSize = 8 )
{
int nError = SUCCESS;
memset( &m_dcb, 0, sizeof( m_dcb ) );
m_dcb.DCBlength = sizeof( m_dcb );
m_dcb.BaudRate = dwBaud;
m_dcb.Parity = iParity;
m_dcb.StopBits = iStopBits;
m_dcb.ByteSize = iByteSize;

if( !::SetCommState( m_hFile, &m_dcb ) )
{
nError = GetLastError();
}
return nError;
}

DWORD TxData( T* szBuf )
{
DWORD nowrote = 0;
memset( m_buf, 0, sizeof( m_buf ) );
if( sizeof( m_buf ) >= strlen( szBuf ) ) // check to see if buffer allocated is big enough
{
memcpy( &m_buf[1], szBuf, strlen( szBuf ) );
m_buf[0] = 0x2;
m_buf[ strlen(szBuf) + 1 ] = 0x3;
return TxData();
}
return BUFFEROVERFLOW;
}

DWORD TxData()
{
DWORD nowrote = 0;
::WriteFile( m_hFile, m_buf, strlen(m_buf), &nowrote, NULL );
return nowrote;
}

CSerialComms( void ){ memset( m_buf, 0, nSize ); };
~CSerialComms(){};


private:
T m_buf[nSize];
COMMTIMEOUTS m_cto;
DCB m_dcb;
HANDLE m_hFile;

enum { FAILED = 0, SUCCESS = 1, BUFFEROVERFLOW = 2 };
};

#endif // !defined(AFX_SERIALCOMMS_H__BA76EBFF_6F02_4E79_BC6 5_DD4C2655354B__INCLUDED_)




Regards,
Steve

high_flyer
22nd May 2007, 13:47
Plenty of serial comms classes on the web...
True, but QextSerialPort is based on QIODevice and therefore integrates well withe Qt Stream classes, and you can sublass it and add signals and slots to it (if you need such a thing, I didn't so far)
And ofcourse, QextSerialPort is cross platform!

shamik
28th May 2007, 12:13
here's wat i have done

Qt Code :


int size;
int *i,j,k;
QFile file("/sfiles/mxdrv.tgz");
if(!file.open( IO_ReadOnly ))
{
QMessageBox::information(0,"Error","Error opening file");
}
else
{
cout<<"File opened successfully"<<endl;
}
cout<<"file opened...."<<endl;
unsigned char fname[]="mxdrv.tgz";

struct termios t;
char *device = "/dev/ttyS0";

int sPort, rbyte, status, sPortdest,length;
long count=0;

unsigned char send1[32];


t.c_cc[VMIN] = 1;
t.c_cc[VTIME]=0;
t.c_cc[VEOF]='\n';

t.c_iflag |= (ISIG);
t.c_iflag &= ~BRKINT;
t.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;

sPort = open(device,O_RDWR|O_NOCTTY|O_NDELAY);

if(sPort != -1)
{
cout<<"open successfully\n";

status = ioctl(sPort,TCSETS,&t);
cout<<"Entering status"<<status<<endl;
if(status==0)
{

//for(count=0;count<20;count++)
cout<<"sending name"<<endl;
rbyte=write(sPort,fname,strlen((char *)send1));
//usleep(3000);
cout<<"name sent"<<endl;
cout<<"now sending file"<<endl;
while(!file.atEnd())

{
//cout<<"Enter :";
//cin>>send1;
//strcat((char *)send1,"{MSS TYPE-D DAMA}");
// write(sPort,"{012345678}",11);
*i=file.getch();
rbyte=write(sPort,i,sizeof(*i));
cout<<rbyte<<"sent"<<endl;
//cout<<"w b:"<<rbyte<<"\t Time:"<<count<<"\t string:"<<send1<<"\n";
//usleep(1000);

}

}
close(sPort);

}
else
{
cout<<"Device could not be opened";
}
file.close();



by running this code from the shell, following is the output :

File opened successfully
file opened....
open successfully
Entering status0
sending name
name sent
now sending file
Segmentation fault


can any1 please tell watz going wrong over here ??

marcel
28th May 2007, 12:18
As far as I can see, int *i is not allocated anywhere.
You must allocate i before you can use it.

Regards

wysota
28th May 2007, 12:19
Don't use "int *i" but "int i". You have an uninitialised pointer. I don't see any reason why would you want to use a pointer to an int, so just use the object directly.

shamik
28th May 2007, 12:48
sorry
please refer the post below

shamik
28th May 2007, 12:51
rather i've used QString with a little bit modification

Code :


int size;
int i,j,k;
QString send="";
QFile file("/sfiles/mxdrv.tgz");
if(!file.open( IO_ReadOnly ))
{
QMessageBox::information(0,"Error","Error opening file");
}
else
{
cout<<"File opened successfully"<<endl;
}
cout<<"file opened...."<<endl;
unsigned char fname[]="mxdrv.tgz";

struct termios t;
char *device = "/dev/ttyS0";

int sPort, rbyte, status, sPortdest,length;
long count=0;

unsigned char send1[32];


t.c_cc[VMIN] = 1;
t.c_cc[VTIME]=0;
t.c_cc[VEOF]='\n';

t.c_iflag |= (ISIG);
t.c_iflag &= ~BRKINT;
t.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;

sPort = open(device,O_RDWR|O_NOCTTY|O_NDELAY);

if(sPort != -1)
{
cout<<"open successfully\n";

status = ioctl(sPort,TCSETS,&t);
cout<<"Entering status"<<status<<endl;
if(status==0)
{

//for(count=0;count<20;count++)
cout<<"sending name"<<endl;
rbyte=write(sPort,fname,strlen((char *)fname));
//usleep(3000);
cout<<"name sent"<<endl;
cout<<"now sending file"<<endl;
while(!file.atEnd())

{
//cout<<"Enter :";
//cin>>send1;
//strcat((char *)send1,"{MSS TYPE-D DAMA}");
// write(sPort,"{012345678}",11);
cout<<"getting byte from file"<<endl;
i=file.getch();
send.sprintf("%d",i);
cout<<send<<endl;
rbyte=write(sPort,send,strlen(send));
cout<<rbyte<<"sent"<<endl;
//cout<<"w b:"<<rbyte<<"\t Time:"<<count<<"\t string:"<<send1<<"\n";
//usleep(1000);

}

}
close(sPort);

}
else
{
cout<<"Device could not be opened";
}
file.close();



when i run the program from the terminal, the bytes get transfered which i can see in the hyperterminal of some other pc.
but then after some time the following comes on the terminal and the program exits abruptly:

*** glibc detected *** ./filetransfer: munmap_chunk(): invalid pointer: 0xbffe8e70 ***
======= Backtrace: =========
/lib/libc.so.6(cfree+0x1bb)[0xe5d67b]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x6874871]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QWidget5closeEb+0x1f6)[0x5198e6]
./filetransfer[0x804fdcb]
./filetransfer[0x804fa3b]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QObject15activate_signalEP15QConnectio nListP8QUObject+0x16a)[0x4dbe2a]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QObject15activate_signalEi+0xbd)[0x4dc95d]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QButton7clickedEv+0x2c)[0x86f8ac]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QButton17mouseReleaseEventEP11QMouseEv ent+0xbd)[0x57fa3d]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QWidget5eventEP6QEvent+0x3c5)[0x5192d5]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication14internalNotifyEP7QObjec tP6QEvent+0x9b)[0x4730fb]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication6notifyEP7QObjectP6QEvent +0x287)[0x474757]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN9QETWidget19translateMouseEventEPK7_XEv ent+0x576)[0x40af26]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication15x11ProcessEventEP7_XEve nt+0x5e6)[0x409a26]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN10QEventLoop13processEventsEj+0x4eb)[0x41b6ab]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN10QEventLoop9enterLoopEv+0x42)[0x48c672]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN10QEventLoop4execEv+0x26)[0x48c536]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication4execEv+0x1f)[0x472c0f]
./filetransfer(_ZN7QWidget6createEmbb+0xe2f)[0x804ef2f]
/lib/lAborted


any suggestions ??

marcel
28th May 2007, 13:09
Well, what button did you pressed?
From the backtrace it seems that you pressed a button.

BTW, do you use threads in your app?

shamik
28th May 2007, 13:14
i dont use any threads in the application

and yes i've pressed a button
actually after pressing that button the code is executed coz the code is written in the click event of that button

marcel
28th May 2007, 13:24
What does close(sPort)?
Can you post the code for that?

wysota
28th May 2007, 13:24
Is it me or are you trying to send a QString object through the line? I'm surprised it even compiles... Provided that your write() calls really mean ::write() then the second argument should be a pointer to a const char* buffer. Could you paste the real and current code you're using? Because I don't think there is a strlen() variant that takes a QString as well...

shamik
28th May 2007, 13:38
the code which i've posted b4 is the one which i m using currently.

if u think sending a QString object cud b erroneous then plz suggest wat 2 use instead. i very well know that the second argument requires const char * but the problem is i dont know how to define/declare it and secondly the getch() function returns an integer, again i donno how to convert that integer into const char * . so i just tried to use QString


i hope now this is not a difficult question 4 u
please help...

marcel
28th May 2007, 13:45
Use QString::toAscii().constData( means const char *).

Regards

high_flyer
29th May 2007, 09:11
And PLEASE - DON'T use sms lingo here! it is so anoying to read it like that, and there is NO reason for it, unless you are posting through WAP on your mobile.

shamik
29th May 2007, 09:18
the function as said above doesnt work
it says theres no such function as QString::toAscii() etc..
anyways i have done some changes to the code. the entire code is as below :


void Form1::send_clicked()
{
int size;
int i,j,k;
QString send;
QFile file("/sfiles/mxdrv.tgz");
if(!file.open( IO_ReadOnly ))
{
QMessageBox::information(0,"Error","Error opening file");
}
else
{
cout<<"File opened successfully"<<endl;
}
cout<<"file opened...."<<endl;
unsigned char fname[]="mxdrv.tgz";
struct termios t;
char *device = "/dev/ttyS0";
int sPort, rbyte, status, sPortdest,length;
long count=0;
unsigned char send1[32];

t.c_cc[VMIN] = 1;
t.c_cc[VTIME]=0;
t.c_cc[VEOF]='\n';

t.c_iflag |= (ISIG);
t.c_iflag &= ~BRKINT;
t.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;

sPort = open(device,O_RDWR|O_NOCTTY|O_NDELAY);

if(sPort != -1)
{
cout<<"open successfully\n";

status = ioctl(sPort,TCSETS,&t);
cout<<"Entering status"<<status<<endl;
if(status==0)
{
//for(count=0;count<20;count++)
cout<<"sending name"<<endl;
rbyte=write(sPort,fname,strlen((char *)fname));
cout<<rbyte<<endl;
QMessageBox::information(0,"sent","Name sent");
//usleep(3000);
cout<<"name sent"<<endl;
cout<<"now sending file"<<endl;
usleep(3000);
while(!file.atEnd())

{
//cout<<"Enter :";
//cin>>send1;
//strcat((char *)send1,"{MSS TYPE-D DAMA}");
// write(sPort,"{012345678}",11);
cout<<"getting byte from file"<<endl;
i=file.getch();
GenerateByte(i,send);
//usleep(3000);
rbyte=TEMP_FAILURE_RETRY( write(sPort,send,qstrlen(send)));
cout<<rbyte<<"sent"<<endl;
//cout<<"w b:"<<rbyte<<"\t Time:"<<count<<"\t string:"<<send1<<"\n";
//usleep(1000);

}

}
close(sPort);
}
else
{
cout<<"Device could not be opened";
}
file.close();
}
void Form1::GenerateByte(int i, QString &ssend)
{
ssend.sprintf("%d",i);
}

and about using the QString object in write() function, i have checked it with the previous code of my project, and it is working fine. The only thing is instead of strlen() i have to use qstrlen().
the code which i have pasted above doesnt give any error while compiling but while transferring file what happens exactly is that the write() function sometimes returns some positive integer and sometimes returnds -1. but most of the time it returns -1.
then after some time the following comes on the terminal :
*** glibc detected *** ./filetransfer: munmap_chunk(): invalid pointer: 0xbfab4940 ***
======= Backtrace: =========
/lib/libc.so.6(cfree+0x1bb)[0xbb267b]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x6874871]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QWidget5closeEb+0x1f6)[0x5198e6]
./filetransfer[0x8050af0]
./filetransfer[0x804fb7f]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QObject15activate_signalEP15QConnectio nListP8QUObject+0x16a)[0x4dbe2a]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QObject15activate_signalEi+0xbd)[0x4dc95d]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QButton7clickedEv+0x2c)[0x86f8ac]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QButton15keyReleaseEventEP9QKeyEvent+0 x5a)[0x57fd5a]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN7QWidget5eventEP6QEvent+0x325)[0x519235]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication14internalNotifyEP7QObjec tP6QEvent+0x9b)[0x4730fb]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication6notifyEP7QObjectP6QEvent +0x54d)[0x474a1d]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN9QETWidget17translateKeyEventEPK7_XEven tb+0x36a)[0x408b0a]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication15x11ProcessEventEP7_XEve nt+0x635)[0x409a75]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN10QEventLoop13processEventsEj+0x4eb)[0x41b6ab]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN10QEventLoop9enterLoopEv+0x42)[0x48c672]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN10QEventLoop4execEv+0x26)[0x48c536]
/usr/lib/qt-3.3/lib/libqt-mt.so.3(_ZN12QApplication4execEv+0x1f)[0x472c0f]
./filetransfer(_ZN7QWidget6createEmbb+0xe37)[0x804f04f]
/lib/libc.so.6(__libc_start_main+0xdc)[0xb5ef2c]
./filetransfer(_ZN11KMainWindow10setCaptionERK7QStri ngb+0x49)[0x804e391]
======= Memory map: ========
00101000-00117000 r-xp 00000000 03:07 483707 /usr/lib/libart_lgpl_2.so.2.3.17
00117000-00118000 rwxp 00016000 03:07 483707 /usr/lib/libart_lgpl_2.so.2.3.17
00118000-0012d000 r-xp 00000000 03:07 686877 /usr/lib/qt-3.3/plugins/styles/bluecurve.so
0012d000-0012e000 rwxp 00015000 03:07 686877 /usr/lib/qt-3.3/plugins/styles/bluecurve.so
00132000-00163000 r-xp 00000000 03:07 483702 /usr/lib/liblcms.so.1.0.15
00163000-00164000 rwxp 00030000 03:07 483702 /usr/lib/liblcms.so.1.0.15
00164000-00167000 rwxp 00164000 00:00 0
00167000-00170000 r-xp 00000000 03:07 487954 /lib/libnss_files-2.5.so
00170000-00171000 r-xp 00008000 03:07 487954 /lib/libnss_files-2.5.so
00171000-00172000 rwxp 00009000 03:07 487954 /lib/libnss_files-2.5.so
00193000-001a5000 r-xp 00000000 03:07 483704 /usr/lib/libXft.so.2.1.2
001a5000-001a6000 rwxp 00012000 03:07 483704 /usr/lib/libXft.so.2.1.2
001a8000-00210000 r-xp 00000000 03:07 483703 /usr/lib/libmng.so.1.0.0
00210000-00213000 rwxp 00067000 03:07 483703 /usr/lib/libmng.so.1.0.0
00215000-00224000 r-xp 00000000 03:07 1329158 /lib/libresolv-2.5.so
00224000-00225000 r-xp 0000e000 03:07 1329158 /lib/libresolv-2.5.so
00225000-00226000 rwxp 0000f000 03:07 1329158 /lib/libresolv-2.5.so
00226000-00228000 rwxp 00226000 00:00 0
0022a000-00a5b000 r-xp 00000000 03:07 196091 /usr/lib/qt-3.3/lib/libqt-mt.so.3.3.6
00a5b000-00a9c000 rwxp 00830000 03:07 196091 /usr/lib/qt-3.3/lib/libqt-mt.so.3.3.6
00a9c000-00aa0000 rwxp 00a9c000 00:00 0
00ab3000-00ac2000 r-xp 00000000 03:07 483684 /usr/lib/libXext.so.6.4.0
00ac2000-00ac3000 rwxp 0000e000 03:07 483684 /usr/lib/libXext.so.6.4.0
00ac3000-00ac4000 r-xp 00ac3000 00:00 0 [vdso]
00ac5000-00ae4000 r-xp 00000000 03:07 1329151 /lib/libexpat.so.0.5.0
00ae4000-00ae6000 rwxp 0001e000 03:07 1329151 /lib/libexpat.so.0.5.0
00ae8000-00b0f000 r-xp 00000000 03:07 483675 /usr/lib/libfontconfig.so.1.1.0
00b0f000-00b17000 rwxp 00027000 03:07 483675 /usr/lib/libfontconfig.so.1.1.0
00b19000-00b21000 r-xp 00000000 03:07 483680 /usr/lib/libXrender.so.1.3.0
00b21000-00b22000 rwxp 00007000 03:07 483680 /usr/lib/libXrender.so.1.3.0
00b24000-00b28000 r-xp 00000000 03:07 483688 /usr/lib/libXfixes.so.3.1.0
00b28000-00b29000 rwxp 00003000 03:07 483688 /usr/lib/libXfixes.so.3.1.0
00b2c000-00b45000 r-xp 00000000 03:07 1329142 /lib/ld-2.5.so
00b45000-00b46000 r-xp 00018000 03:07 1329142 /lib/ld-2.5.so
00b46000-00b47000 rwxp 00019000 03:07 1329142 /lib/ld-2.5.so
00b49000-00c80000 r-xp 00000000 03:07 1329143 /lib/libc-2.5.so
00c80000-00c82000 r-xp 00137000 03:07 1329143 /lib/libc-2.5.so
00c82000-00c83000 rwxp 00139000 03:07 1329143 /lib/libc-2.5.so
00c83000-00c86000 rwxp 00c83000 00:00 0
00c88000-00cad000 r-xp 00000000 03:07 1329150 /lib/libm-2.5.so
00cad000-00cae000 r-xp 00024000 03:07 1329150 /lib/libm-2.5.so
00cae000-00caf000 rwxp 00025000 03:07 1329150 /lib/libm-2.5.so
00cb1000-00cb3000 r-xp 00000000 03:07 1329144 /lib/libdl-2.5.so
00cb3000-00cb4000 r-xp 00001000 03:07 1329144 /lib/libdl-2.5.so
00cb4000-00cb5000 rwxp 00002000 03:07 1329144 /lib/libdl-2.5.so
00cb7000-00cca000 r-xp 00000000 03:07 1329145 /lib/libpthread-2.5.so
00cca000-00ccb000 r-xp 00012000 03:07 1329145 /lib/libpthread-2.5.so
00ccb000-00ccc000 rwxp 00013000 03:07 1329145 /lib/libpthread-2.5.so
00ccc000-00cce000 rwxp 00ccc000 00:00 0
00cd0000-00ce2000 r-xp 00000000 03:07 483673 /usr/lib/libz.so.1.2.3
00ce2000-00ce3000 rwxp 00011000 03:07 483673 /usr/lib/libz.so.1.2.3
00ce5000-00cea000 r-xp 00000000 03:07 483678 /usr/lib/libXdmcp.so.6.0.0
00cea000-00ceb000 rwxp 00004000 03:07 483678 /usr/lib/libXdmcp.so.6.0.0
00ced000-00cef000 r-Aborted

i dont know wat does this mean.

can any1 please find watz going wrong

marcel
29th May 2007, 09:24
When I said QString::toAscii().constData() I meant the method name and location.
But now I see you're using Qt3. Sorry about that :).
In Qt3 you must use send.ascii(). This will give you a const char*.
And you must use this, because the code is still not correct.

For length, you can use send.length() or send.size(). I don't know which one is available in Qt3.

Regards

shamik
29th May 2007, 10:00
i've used send.ascii() instead of send

the qstrlen() function perfectly gives the length of the string so i dont think the problem is there.

still the output is the same.
the write() function which returns -1 only when there is an error while sending, and some other digit when data is sent corrently, most of the time gives -1 and only few times somewhere in between gives some other digits.
later after some more time, the above mentioned error comes

i donno wat is wrong over here. i think now its becoming difficult to find out.

high_flyer
29th May 2007, 10:03
For length, you can use send.length() or send.size(). I don't know which one is available in Qt3.
The reason is, that qstrlen() returns the length of the given string, but QString is not a string, its a class that manages a string, so QString is an object containing a string.
send.length() will return the length of the string it self which is contained by the QString object.

you posted your last post while I was writing mine so:

the qstrlen() function perfectly gives the length of the string so i dont think the problem is there.
I can't explain this, it should not be so, because of the explanation above.
You are giving a QString object to qstrlen() and it awaits a const char*.
As wysota said, this should not even compile.

marcel
29th May 2007, 10:17
qstrlen works because QString has operator const char * overloaded in Qt3.
But it is recommended not to be used.

marcel
29th May 2007, 10:22
The only thing is instead of strlen() i have to use qstrlen().
the code which i have pasted above doesnt give any error while compiling but while transferring file what happens exactly is that the write() function sometimes returns some positive integer and sometimes returnds -1. but most of the time it returns -1.


See what is the value of errno after write returns -1.
Something like this( from MSDN ):


if (( bytesWritten = _write( fileHandle, buffer, sizeof( buffer ))) == -1 )
{
switch(errno)
{
case EBADF:
perror("Bad file descriptor!");
break;
case ENOSPC:
perror("No space left on device!");
break;
case EINVAL:
perror("Invalid parameter: buffer was NULL!");
break;
default:
// An unrelated error occured
perror("Unexpected error!");
}
}

Regards