Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    qstring contains break point qserialport terminal
    1
    2
    1354
    Loading More Posts
    • 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
      Sen Li last edited by Sen Li

      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 Reply Quote 0
      • S
        Sen Li last edited by Sen Li

        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 Reply Quote 0
        • First post
          Last post