Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to exit void QIODevice::readyRead() function ? Is this function also interrupt?
Forum Updated to NodeBB v4.3 + New Features

How to exit void QIODevice::readyRead() function ? Is this function also interrupt?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
31 Posts 4 Posters 3.6k Views
  • 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.
  • M Offline
    M Offline
    Mucahit
    wrote on last edited by Mucahit
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • M Mucahit

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mucahit I don't understand the problem. Can you rephrase?
      To exit a function/method you simply do a return;

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • M Offline
        M Offline
        Mucahit
        wrote on last edited by Mucahit
        #3

        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.

        jsulmJ 1 Reply Last reply
        0
        • M Mucahit

          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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • M Offline
            M Offline
            Mucahit
            wrote on last edited by
            #5

            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.

            jsulmJ 1 Reply Last reply
            0
            • M Mucahit

              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.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by jsulm
              #6

              @Mucahit Can you show your code? Especially slot connected to readyRead().

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mucahit
                wrote on last edited by
                #7

                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
                }

                jsulmJ J.HilkJ 2 Replies Last reply
                0
                • M Mucahit

                  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
                  }

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mucahit
                    wrote on last edited by
                    #9

                    Does not print this data without moving the mouse. So I can't get out of this readyread function and switch to paintevent.

                    1 Reply Last reply
                    0
                    • M Mucahit

                      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
                      }

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #10

                      @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();
                      }
                      

                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      3
                      • M Offline
                        M Offline
                        Mucahit
                        wrote on last edited by
                        #11

                        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();
                        }

                        JonBJ J.HilkJ jsulmJ 3 Replies Last reply
                        0
                        • M Mucahit

                          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();
                          }

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #12

                          @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.

                          1 Reply Last reply
                          3
                          • M Mucahit

                            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();
                            }

                            J.HilkJ Offline
                            J.HilkJ Offline
                            J.Hilk
                            Moderators
                            wrote on last edited by
                            #13

                            @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


                            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                            Q: What's that?
                            A: It's blue light.
                            Q: What does it do?
                            A: It turns blue.

                            1 Reply Last reply
                            1
                            • M Mucahit

                              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();
                              }

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by jsulm
                              #14

                              @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?

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              2
                              • M Offline
                                M Offline
                                Mucahit
                                wrote on last edited by
                                #15

                                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.

                                jsulmJ 1 Reply Last reply
                                0
                                • M Mucahit

                                  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.

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @Mucahit You can redraw completely based on updated data. If paintEvent() is called the previously drawn content is deleted.

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • M Offline
                                    M Offline
                                    Mucahit
                                    wrote on last edited by
                                    #17

                                    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 ?

                                    jsulmJ 1 Reply Last reply
                                    0
                                    • M Mucahit

                                      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 ?

                                      jsulmJ Offline
                                      jsulmJ Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on last edited by jsulm
                                      #18

                                      @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.

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      1
                                      • M Offline
                                        M Offline
                                        Mucahit
                                        wrote on last edited by
                                        #19

                                        I understood very well what you said. Yes i have a protocol but i can't trigger paintevent.

                                        jsulmJ 1 Reply Last reply
                                        0
                                        • M Mucahit

                                          I understood very well what you said. Yes i have a protocol but i can't trigger paintevent.

                                          jsulmJ Offline
                                          jsulmJ Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #20

                                          @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.

                                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          1 Reply Last reply
                                          0

                                          • Login

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