[SOLVED] QString.Contains Code works only with break point, does not work if no break point
General and Desktop
2
Posts
1
Posters
1.6k
Views
1
Watching
-
wrote on 2 Apr 2015, 00:47 last edited by Sen Li 4 Feb 2015, 17:00
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!
-
wrote on 2 Apr 2015, 16:58 last edited by Sen Li 4 Feb 2015, 16:59
I added a delay function before reading the serial port,
console->SenDelay(70); QByteArray data = serial->readAll();
now everything is working.
1/2