Results 1 to 3 of 3

Thread: IF-Statement problem

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default IF-Statement problem

    hi everyone, i have the "if" statement below. the purpose of this 'if' statement is to check if the string 'LoginDetail@#%$^*&_FhDKooKSE' is contained in the QByteArray 'readAll', if the condition is true the 'else' part of the 'if' statement is executed otherwise whatever is in the QByteArray is displayed on screen. the else part works fine but the 'false' condition displays empty strings even though there is something to display in the QByteArray. I think this is because the statement 'socket.readAll()' is executed twice, first in the condition of the 'if' statement secondly just below the 'if' statement.
    Qt Code:
    1. void Client::readSocket()
    2. {
    3.  
    4. if(!socket->readAll().contains("LoginDetail@#%$^*&_FhDKooKSE"))
    5. qDebug() << socket->readAll() <<endl;
    6. else
    7. qDebug() << "Login window is opened";
    8. }
    To copy to clipboard, switch view to plain text mode 

    how can i fix this.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: IF-Statement problem

    I think this is because the statement 'socket.readAll()' is executed twice, first in the condition of the 'if' statement secondly just below the 'if' statement.
    Yes, so make it execute once and reuse the result.

  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: IF-Statement problem

    thank you for your reply, I have solved the problem like below. Yeah... i admit i was lazy to think.
    Qt Code:
    1. void Client::readSocket()
    2. {
    3. QByteArray tempByteArray = socket->readAll();
    4. if(!tempByteArray.contains("LoginDetail@#%$^*&_FhDKooKSE"))
    5. qDebug() << tempByteArray <<endl;
    6. else
    7. qDebug() << "Login window is opened";
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 22nd August 2013, 16:49
  2. Connect statement problem
    By Bender_Rodriguez in forum Newbie
    Replies: 4
    Last Post: 14th April 2013, 20:34
  3. How to get value from a query statement ?
    By hohoanganh205 in forum Newbie
    Replies: 3
    Last Post: 5th January 2012, 14:23
  4. QSqlQuery problem with SELECT statement
    By virtuosite in forum Newbie
    Replies: 2
    Last Post: 31st August 2009, 08:13
  5. SmartFOSS Mission Statement
    By travlr in forum Qt-based Software
    Replies: 0
    Last Post: 16th April 2007, 05:41

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.