Solved QSerialPort
-
@mvsri said in QSerialPort:
it loop's itself in the Pushbutton_write() function
That's not clear. Can you show what exactly you're doing there?
-
@jsulm
i meant once i clicked on the pushbutton_write, i get continuous qInfo() in Application Outputvoid MainWindow::on_pushButton_write_clicked() { QString Result = ui->lineEdit->text(); QString request = "\x02"+QString("003")+ QString("%1").arg(Result.toInt(),7,10,QChar('0')) +"\r"; const QByteArray requestData = request.toUtf8(); serial->write(requestData); qInfo() << "Data Write: " << requestData; }
According to the logic of the above code when i press PushButton the code should write the data and print the data only once.
Although what happens is as soon as i press PushButton the whole on_pushButton_write_clicked() function goes into loop(like repeating the pushbutton fucntion itself)by sending write data using serial->write() and printing the qInfo() in Application Output.
-
@mvsri Maybe you connected on_pushButton_write_clicked() to some other signal?
-
@mvsri said in QSerialPort:
"\x02"+QString("003")
Since \x02 is no valid QString char I would not use QString here in the first place. You will get problems sooner or later with this.
-
@mvsri I would try to define the slot by hand and explicitly call the QObject::connect to connect signal and slot.
The connectSlotByName meta-method is known to behave not exactly consistent 😄
-
@jsulm NO i haven't connected it to any other signal, infact if you could check the mainwindow.cpp you can see that i haven't connected it.
-
Then please comment all the code within
MainWindow::on_pushButton_write_clicked()
and just add aqDebug() << "on_pushButton_write_clicked";
in it.If you click the button once, you should see that message also one time. Does that work?
Regards
-
i used QObject::connect to connect signal and slot and it solved the problem.
Thank you for the help!
-
Glad you figured it out. So please mark this topic as SOLVED too. Thanks!
-
@mvsri please can you paste the code or explain more how QObject::connect .
-
Please see here: https://doc.qt.io/qt-5/signalsandslots.html