Results 1 to 10 of 10

Thread: QStringList::contains() not working

  1. #1
    Join Date
    May 2008
    Location
    USA
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink QStringList::contains() not working

    Hello,
    I'm trying to find a string inside a QStringList which is in a loop, but it doesn't seem to be working. I'm not sure whether I'm doing it right or not.
    I tried debugging it for hours with no luck. It might be the way I'm parsing the data coming from the QTcpSocket ?
    Am i doing it wrong?

    The code is below:

    Qt Code:
    1. void Core::connected()
    2. QTextStream in(tcpSocket);
    3. QString data;
    4. do
    5. {
    6. data = in.readLine();
    7. QStringList words = data.split(" ");
    8.  
    9. if ( words.count() > 2 )
    10. {
    11. // at this point, words should be something like = ("nmuntz@localhost", "MSG", ":VERSION");
    12. if ( words.contains(":VERSION", Qt::CaseInsensitive) )
    13. qDebug() << "words contains the word version!!!";
    14. }
    15.  
    16. while ( !in.atEnd() ) ;
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot in advance!
    Greetings.

  2. #2
    Join Date
    Feb 2006
    Posts
    26
    Thanked 2 Times in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QStringList::contains() not working

    Hi,

    2 maybe 3 ideas:

    - add a qDebug() statement too in case you don't find the searched string: maybe the debug line is not displayed because you forgot something like 'qt+= console' in your .pro file.

    - display (in a qDebug) the content of the QStringList, thus, you'll ensure that what you are searching for is REALLY inside the list.

    On my side, i bet you don't have what expected in your string list.

  3. #3
    Join Date
    May 2008
    Location
    USA
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: QStringList::contains() not working

    Hi,
    First, thanks for the quick reply !
    Quote Originally Posted by nouknouk View Post
    Hi,

    2 maybe 3 ideas:

    - add a qDebug() statement too in case you don't find the searched string: maybe the debug line is not displayed because you forgot something like 'qt+= console' in your .pro file.
    Debugging is correctly working in my program, I have other qDebug() lines and they are correctly working...

    Quote Originally Posted by nouknouk View Post
    - display (in a qDebug) the content of the QStringList, thus, you'll ensure that what you are searching for is REALLY inside the list.

    On my side, i bet you don't have what expected in your string list.
    I already tried displaying the content of the QStringList, but my program ends unexpectedly with a
    Qt Code:
    1. ASSERT failure in QList<T>::operator[]: "index out of range", file /usr/include/QtCore/qlist.h, line 399
    To copy to clipboard, switch view to plain text mode 

    Greetings,

  4. #4
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList::contains() not working

    use
    Qt Code:
    1. qDebug()<<words;
    To copy to clipboard, switch view to plain text mode 
    to see what exactly contain your QStringList

  5. #5
    Join Date
    May 2008
    Location
    USA
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStringList::contains() not working

    Quote Originally Posted by mazurekwrc View Post
    use
    Qt Code:
    1. qDebug()<<words;
    To copy to clipboard, switch view to plain text mode 
    to see what exactly contain your QStringList
    here is the output of the last 2 lines:
    words is: (":nmuntz@localhost", "MODE", "nmuntz", ":+iw")
    words is: (":nmuntz@localhost", "MSG", "nmuntz", ":VERSION")
    so my code, when the last line appears, should be doing something......

  6. #6
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList::contains() not working

    could you copy your original code from your file, becouse I see in that code which you insert few syntax mistakes so I think you don't use copy/paste, maybe there are some other difference and we can't see them

  7. #7
    Join Date
    May 2008
    Location
    USA
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QStringList::contains() not working

    Quote Originally Posted by mazurekwrc View Post
    could you copy your original code from your file, becouse I see in that code which you insert few syntax mistakes so I think you don't use copy/paste, maybe there are some other difference and we can't see them
    the code I posted is exactly the code I'm using... I just tried recoding the function with a copy paste of the code I pasted here and it's not working...
    This is really strange, because it should be working...

    Im pretty sure it has to do with the way im handling the QTextStream from the tcpSocket... there's something about that loop that doesn't seem right...

  8. #8
    Join Date
    Oct 2007
    Location
    Cracow
    Posts
    56
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QStringList::contains() not working

    the code I posted is exactly the code I'm using... I just tried recoding the function with a copy paste of the code I pasted here and it's not working...
    This is really strange, because it should be working...
    becouse this code have syntax mistakes for example
    Qt Code:
    1. do
    2. {
    3. while( !in.atEnd() ) ;
    4. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QStringList::contains() not working

    Yes i think the same ...

    here so you can grab line....

    Qt Code:
    1. if (m_Socket->waitForReadyRead(Timeout)) {
    2. qDebug() << "### connect ok port " << url.port();
    3. QTextStream *t = new QTextStream( m_Socket );
    4. t->setCodec(QTextCodec::codecForMib(106));
    5. int loops = -1;
    6. while (!t->atEnd()) {
    7. loops++;
    8. response = t->readLine();
    9. qDebug() << loops << " line " << response;
    10. }
    11. emit result(url.port(),runtime(st),true);
    12. quit();
    13. } else {
    To copy to clipboard, switch view to plain text mode 

    Have a look on portscanner sample..

    http://www.qtcentre.org/forum/f-qt-p...ner-13733.html

  10. #10
    Join Date
    May 2008
    Location
    USA
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation Re: QStringList::contains() not working

    patrick08:

    Ok, so I used your code:
    Qt Code:
    1. void QtBotCore::connected()
    2. {
    3. QTextStream *t = new QTextStream( tcpSocket );
    4. QString response;
    5. int loops = -1;
    6. while ( !t->atEnd() )
    7. {
    8. loops++;
    9. response = t->readLine();
    10. qDebug() << loops << " line " << response;
    11.  
    12. if ( response.contains(":VERSION") )
    13. qDebug() << "IT WORKED !";
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    And the output is something like this:
    0 line "127.0.0.1 372 nmuntz :- ____ _____ _______ ____ ____ _"
    1 line ":127.0.0.1 372 nmuntz :- | _ \ / _ \ \ / / ____| _ \/ ___| ___| |"
    2 line ":127.0.0.1 372 nmuntz :- Welcome to Server"
    3 line ":127.0.0.1 372 nmuntz :- "
    4 line ":127.0.0.1 376 nmuntz :End of /MOTD command."
    5 line ":nmuntz MODE nmuntz :+iw"
    6 line ":Global!services@powers.cl NOTICE nmuntz :[Logon News - May 03 2006] PWN!"
    7 line ":nmuntz@pool.verizon.net PRIVMSG nmuntz :VERSION"

Similar Threads

  1. QDevelop and CTags -> Not working
    By philwinder in forum Qt-based Software
    Replies: 13
    Last Post: 9th May 2008, 21:40
  2. Don't want QTextBrowser to look in working directory
    By magland in forum Qt Programming
    Replies: 1
    Last Post: 20th October 2007, 23:14
  3. GUI thread and Working thread comunication
    By FasTTo in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2007, 15:31
  4. Mac OS X UI not working
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2006, 01:02
  5. Signals/Slots stopped working
    By Jimmy2775 in forum Qt Programming
    Replies: 8
    Last Post: 31st March 2006, 21:11

Tags for this Thread

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.