Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QString.Contains Code works only with break point, does not work if no break point
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QString.Contains Code works only with break point, does not work if no break point

Scheduled Pinned Locked Moved General and Desktop
qstringcontainsbreak pointqserialportterminal
2 Posts 1 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sen Li
    wrote on 2 Apr 2015, 00:47 last edited by Sen Li 4 Feb 2015, 17:00
    #1

    I am a beginner on QSerialPort Terminal Example.
    Whenever my sensor initialization happens, SerialPort should receive data string that contains the menu selection string SenInitialMenuString as shown below.

    Here is my code:

    void MainWindow::readData()
    {

    QString SenDataString;
    QString SenInitialMenuString = "------SparkFun SPI Shortcut------\n\r\n\rMAIN MENU:\n\r(1) Actions\n\r(2) Settings\n\r\n\r->";
    
    QByteArray data = serial->readAll();
    console->putData(data);
    
    SenDataString = data;
    if(SenDataString.contains(SenInitialMenuString))
    {
        qDebug("\nThis is the %d time initialization", ++NumOfInitial);
        SenFakeKey = new QKeyEvent(QEvent::KeyPress,Qt::Key_1,Qt::NoModifier, "1",false,1);
        console->SenFakeKeyPressEvent(SenFakeKey);
    }
    

    }


    However, this code works very well only if I add a break point at the line of
    " if(SenDataString.contains(SenInitialMenuString))",
    whenever I run the code with no break point, it will pass it like it was never there.

    Could anyone help me find out what is going on ?

    Thanks!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Sen Li
      wrote on 2 Apr 2015, 16:58 last edited by Sen Li 4 Feb 2015, 16:59
      #2

      I added a delay function before reading the serial port,

      console->SenDelay(70);
      QByteArray data = serial->readAll();
      

      now everything is working.

      1 Reply Last reply
      0

      1/2

      2 Apr 2015, 00:47

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved