1 Attachment(s)
Using QTcpSockt to check an IMAP server
Hello there,
I have some troubles using QTcpSocket (Qt4)
My code does those simple steps :
- Connect to an IMAP server
- Login (with username / password pair)
- Look for new messages (if any)
- Logout
I checked the FortuneThreaded in the Qt4 doc, and tried to do something similar...
but it doesn't work that much : it seems I can only connect to server...
And the program seems to close unexpectedly, even if I put some sleep events...
I joined my two files in attachment !
Thanks in advance for any help,
Guilugi.
PS : I had some similar code made with Qt3, and it works perfectly, I'm sure that's a silly mistake from me :p
Re: Using QTcpSockt to check an IMAP server
Quote:
Originally Posted by guilugi
Hello there,
I checked the FortuneThreaded in the Qt4 doc, and tried to do something similar...
but it doesn't work that much : it seems I can only connect to server...
And the program seems to close unexpectedly, even if I put some sleep events...
I think that it is because you have to call the:
waitForBytesWritten() and bytesAvailable() functions after read and write.
If you don't use signals/slots to send/receive you have to use these methos to work synchronously.
Another thing could be that you could try to use a longer timeout when trying to connect:
socket.waitForConnected(-1)
sometime I have noticed that the socket hangs if it cannot connect immediatly.
I hope it will help.
Simone
Re: Using QTcpSockt to check an IMAP server
Hey !
First, thanks for your reply.
Well, yes, I applied a Qt3 approach that isn't valid with Qt4, I completely forgot about those wait signals...
But I still have some problems with my method writeToSocket()...which doesn't seem to write data...at all
And when I add a waitForReadyRead(-1), the app loops...
Any idea ?
Thanks again,
Guilugi.
Re: Using QTcpSockt to check an IMAP server
Quote:
Originally Posted by guilugi
Hey !
But I still have some problems with my method writeToSocket()...which doesn't seem to write data...at all
And when I add a waitForReadyRead(-1), the app loops...
Any idea ?
Post the new code,please.
1 Attachment(s)
Re: Using QTcpSockt to check an IMAP server
Re: Using QTcpSockt to check an IMAP server
Hrmmm. Try to pass the socket as a pointer and not as a reference, I
mean:
Using copy constructor you force the creation of a copy object and destruction of it. Passing pointer you don't. I think that in this process, you close the original socket and create a new,disconnected one.
Before doing this change you can try to call state() on the socket to check if it is connected or nor.
I also advice you to use a statement like:
Code:
if( waitForBytesWritten(timeOut) ) return 0;
else return -1;
to control the write event.
Re: Using QTcpSockt to check an IMAP server
Okay,
I made some modifications as you told me,...but problem is still here.
Socket seems to get stuck when writing some bytes....
Thanks anyway, I'll check again my code this evening.
Guilugi
Re: Using QTcpSockt to check an IMAP server
Quote:
Originally Posted by guilugi
Okay,
I made some modifications as you told me,...but problem is still here.
Socket seems to get stuck when writing some bytes....
Thanks anyway, I'll check again my code this evening.
Guilugi
Have you tried to call state() on the socket to monitor its dis/connected state?
And,moreover,have you passed the socket as a pointer ALSO to the checkInbox function?
Quote:
Originally Posted by guilugi
Thanks anyway, I'll check again my code this evening.
Guilugi
You are welcome!;)
1 Attachment(s)
Re: Using QTcpSockt to check an IMAP server
Yes sir, I changed both functions :)
I also connected my socket to stateChanged() to monitor, and I did a little call to state() in writeToSocket()...
and it returns 3 -> Connection Established...
I attached the new file !
Thanks,
Guilugi.
PS : I'm quite new to QtNetwork with Qt4, it seems far more complex than Qt3...but far more powerful too :)
Re: Using QTcpSockt to check an IMAP server
Ohhh, I realized that you used QTextStream to write on the socket...:p
You have to use QDataStream to write on a socket.
Re: Using QTcpSockt to check an IMAP server
Well, I used QDataStream at first, and then I switched to see if it made a difference !
But, once again, that doesn't solve my problem ;)
You know, this code exists in a Qt3 version, and it works like a charm...
Meantime, a Qt developer is having a look at it, and if he finds out (I hope so ;) ),
I'll keep you in touch.
Guilugi.
Re: Using QTcpSockt to check an IMAP server
Hi,
Finally got some news from the Qt guy :)
It seems there is a bug with QTcpSocket in Qt4.1.1...
He'll try to fix it soon ;)
Guilugi.
Re: Using QTcpSockt to check an IMAP server
Quote:
Originally Posted by guilugi
Hi,
Finally got some news from the Qt guy :)
It seems there is a bug with QTcpSocket in Qt4.1.1...
He'll try to fix it soon ;)
Guilugi.
Keep me updated!:)