Results 1 to 8 of 8

Thread: Pop3

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    45
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows
    Thanks
    17

    Exclamation Re: Pop3

    I have to admit, that I don't understand something in "How does qDebug() << message work?". Apparently, at any one time, when we call qDebug() << something; something suppose to appear in the console, isn't it? But in this piece of code it will not work in a right way:
    Qt Code:
    1. socket->write("LIST\r\n");
    2. QString str;
    3. while(socket->waitForReadyRead())
    4. {
    5. str = socket->readAll().data();
    6. qDebug() << str;
    7. qDebug() << str.length();
    8. }
    To copy to clipboard, switch view to plain text mode 

    I will not get the length of the string in the console. I tried to put a break-point. Yes, program will stop on that point, but once again there is no result on the screen for some reason. May be I need to include something in .pro file, besides QT += network. I don't know. Could you please explain me, what's going on behind the scene in qDebug() and why it will not show any results?

    Thank you beforehand.

    p.s. I consider the worst scenario, when message will be received by chunks. In this case either once the length will be shown or nothing at all.
    p.p.s. I solved problem in this way:

    Qt Code:
    1. socket->write("LIST\r\n");
    2. while(socket->waitForReadyRead())
    3. {
    4. arr.insert(arr.length(), socket->readAll());
    5. qDebug() << arr.data();
    6. qDebug() << "Length: " << arr.length();
    7. if(arr.endsWith(".\r\n"))
    8. break;
    9. }
    To copy to clipboard, switch view to plain text mode 

    I got the right result. But why for the QString it doesn't work? I'm a bit confused. In the world of C++
    Qt Code:
    1. std::cout
    To copy to clipboard, switch view to plain text mode 
    works perfectly. And we always can grab the right result for the string length... Honestly, I don't get it, how does qt interpret length-function for the QString...
    Last edited by DmitryNik; 17th September 2011 at 11:57.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Pop3

    Qt Code:
    1. socket->write("LIST\r\n");
    2. QString str;
    3. while(socket->waitForReadyRead())
    4. {
    5. str = socket->readAll().data();
    6. qDebug() << str;
    7. qDebug() << str.length();
    8. }
    To copy to clipboard, switch view to plain text mode 
    You are retrieving a bunch of bytes into a QByteArray using QTcpSocket::readAll(). This may not be any sort of character data (although it should be for POP3) or a complete message. You then assume the content of the array is a C-style string (QByteArray::data()) and assign it to a QString. QString:perator=() runs it through fromAscii() which, depending what is actually in the data and the current codec settings, may do odd things to it. After that QString will report the number of characters in the QString.

    On Windows you may need "CONFIG += console" to get console output when a debugger is not present.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  3. The following user says thank you to ChrisW67 for this useful post:

    DmitryNik (18th September 2011)

  4. #3
    Join Date
    Sep 2011
    Posts
    45
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows
    Thanks
    17

    Question Re: Pop3

    Thank you. Now I understand that. I presume, I can use only QByteArray, without QString.

    BTW, I have one question: does qt have the class, which is related to readers-writers problem? Or we still need to write something like that:

    Qt Code:
    1. while(true)
    2. {
    3. mutex.acqure();
    4. readcount++;
    5. if(readcount == 1) mutex.acqure();
    6. mutex.release();
    7.  
    8. //critical section
    9.  
    10. mutex.acqure();
    11. readcount--;
    12. if(readcount == 0) mutex.release();
    13. mutex.release();
    14. }
    To copy to clipboard, switch view to plain text mode 

    In C#, for instance, we have ReaderWriterLockSlim class, which reduce amount of code.
    Last edited by DmitryNik; 18th September 2011 at 10:17.

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Talking Re: Pop3

    Have a look at QMutex and the See Also list on that page.

  6. The following user says thank you to ChrisW67 for this useful post:

    DmitryNik (19th September 2011)

  7. #5
    Join Date
    Sep 2011
    Posts
    45
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows
    Thanks
    17

    Default Re: Pop3

    Thank you once again for clarifying.

    p.s. yeah, that thread is not only about pop3 now =D

Similar Threads

  1. Stopping the download process during pop3 session.
    By kremuwa in forum Qt Programming
    Replies: 2
    Last Post: 28th July 2010, 23:41
  2. Replies: 3
    Last Post: 9th July 2010, 20:55
  3. Replies: 2
    Last Post: 4th July 2010, 22:49
  4. Downloading specific mails using POP3 protocol.
    By kremuwa in forum General Programming
    Replies: 1
    Last Post: 22nd May 2010, 10:06
  5. Simply Client E-mail (POP3)
    By Altertwin in forum Qt Programming
    Replies: 5
    Last Post: 25th February 2010, 17:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.