Solved How to exit void QIODevice::readyRead() function ? Is this function also interrupt?
-
Hello everyone,
I am reading my data with serial.readall function. In mainwindow function, I am printing my data with qdebug. I get my data properly, no problem, but in order to return to mainwindow function, I need to pass the mouse over the button. How do I get out of this function(QIODevice::readyRead()) without doing this. Thank you all.
-
@Mucahit I don't understand the problem. Can you rephrase?
To exit a function/method you simply do a return; -
When my program is working in the main function, when the data comes from the serial port, it calls the readyread function automatically. But to exit this function, I need to pass it over the mouse button. How can I get it out of this function when it has finished receiving data? More precisely, how can I get the mouse to leave without passing over any button?
The event I want is this: When the data comes from the serial port, it will automatically go and get that data and return it to my screen and print it. Since I do not want to do any operation in the interrupt function, I want it to be done after exiting that function. I used the atEnd() function but it didn't work
I'm sorry for my bad english.
-
@Mucahit I still don't get what readyRead has to do with mouse cursor. If you want to do something after readyRead finishes you could use QTimer for example. But since I don't really understand what you're describing I don't know...
-
Because after the readyread function works, it doesn't shut down unless I move the mouse.Readyread function gets stuck. I want to leave this function when the last data import is finished. The atEnd() function should work for this but it didn't work.
-
@Mucahit Can you show your code? Especially slot connected to readyRead().
-
Of course,
QByteArray data;
QByteArray totaldata;void QIODevice::readyRead()
{
data=serial.readAll();
totaldata=totaldata+data;
}void MainWindow::paintEvent(QPaintEvent *)
{
qDebug()<<totaldata; // I want to print the data I receive here because I will draw pies based on the data I received
} -
@Mucahit said in How to exit void QIODevice::readyRead() function ? Is this function also interrupt?:
I want to print the data I receive here because I will draw pies based on the data I received
And what is the problem?
-
Does not print this data without moving the mouse. So I can't get out of this readyread function and switch to paintevent.
-
@Mucahit said in How to exit void QIODevice::readyRead() function ? Is this function also interrupt?:
paintEvent is not being called, just because totalData changed ...
try calling update() it will schedule a paint event call at the next possible time.
void QIODevice::readyRead() { data=serial.readAll(); totaldata=totaldata+data; update(); }
-
Yes that's exactly what i want but the update function didn't work.
I had to use the update function like this:
void QIODevice::readyRead()
{
data=serial.readAll();
totaldata=totaldata+data;
QMainWindow main;
main.update();
} -
@Mucahit said in How to exit void QIODevice::readyRead() function ? Is this function also interrupt?:
QMainWindow main;
main.update();You really can't do this. That is a local variable, it has nothing to do with your main window. This is basic C++ stuff.
-
@Mucahit said in How to exit void QIODevice::readyRead() function ? Is this function also interrupt?:
void QIODevice::readyRead()
{
data=serial.readAll();
totaldata=totaldata+data;
QMainWindow main;
main.update();
}this should do nothing, that creates a new main window and destroys it immediately, you don't event show() it.
You have to signal your mainwinow instance to update, do that via a custom signal, emitted from your iodevice
-
@Mucahit said in How to exit void QIODevice::readyRead() function ? Is this function also interrupt?:
QMainWindow main;
?
You create a NEW QMainWindow instance here!
Why don't you simply try to actually draw anything in your paintEvent? -
I dont know how to do i am new in qt and c ++. I do not know how to renew my previously found chart pie in my main window with any data I read from the serial port. When the application is first opened, the chart pie is painted with 50 percent, but it will be 70 percent when any value comes from the serial port. Sorry for bothering you.
-
@Mucahit You can redraw completely based on updated data. If paintEvent() is called the previously drawn content is deleted.
-
But I want to do this outside the readyread function when all the data reading is finished, so that it does not hinder my data reading speed. How can I do that ?
-
@Mucahit First: you do it already outside of readyRead()! update() does not call paintEvent() directly, it only puts the event in the event queue. Second: do you have a protocol or how do you know when the reading is done? If you have a protocall when you can use a bool variable which is set to true when all data was read (and call update()) and use this variable inside paintEvent() to check whether you need to paint or not.
-
I understood very well what you said. Yes i have a protocol but i can't trigger paintevent.
-
@Mucahit said in How to exit void QIODevice::readyRead() function ? Is this function also interrupt?:
but i can't trigger paintevent
Why not? You just need to store received data, set a bool flag and call update.