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?
Qt 6.11 is out! See what's new in the release blog

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 5.2k 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
    #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
                                  • M Offline
                                    M Offline
                                    Mucahit
                                    wrote on last edited by Mucahit
                                    #21

                                    Now my code is below:

                                    QByteArray data;
                                    QByteArray totaldata;

                                    void QIODevice::readyRead()
                                    {
                                    data=serial.readAll();
                                    totaldata=totaldata+data;
                                    if(totaldata=="xFe/xD3/xFD")
                                    {
                                    MainWindow main;
                                    main.update();
                                    // or main.repaint();
                                    }
                                    }
                                    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
                                    }

                                    I see the data i read from the serial port in the output of this code, right? But i don't see anything. As i said, i can only get my qdebug output when I hover my mouse over the window. It never prints that value on the screen if I don't move it.

                                    jsulmJ 1 Reply Last reply
                                    0
                                    • M Mucahit

                                      Now my code is below:

                                      QByteArray data;
                                      QByteArray totaldata;

                                      void QIODevice::readyRead()
                                      {
                                      data=serial.readAll();
                                      totaldata=totaldata+data;
                                      if(totaldata=="xFe/xD3/xFD")
                                      {
                                      MainWindow main;
                                      main.update();
                                      // or main.repaint();
                                      }
                                      }
                                      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
                                      }

                                      I see the data i read from the serial port in the output of this code, right? But i don't see anything. As i said, i can only get my qdebug output when I hover my mouse over the window. It never prints that value on the screen if I don't move it.

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

                                      @Mucahit Sorry, but this code does not make any sense! You already were told that creating a temporary QMainWindow instance and calling update() on it is simply wrong! You need to call update on your widget where you want to paint.
                                      I suggest you take time to check some paintEvent examples, like https://doc.qt.io/qt-5/qtwidgets-widgets-analogclock-example.html

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

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

                                        Thank you sir, i know how i can make a watch. All i want is to call paintevent in readyread function and i couldn't solve this problem. All i want is a line of code not an article, i can't. Please can you share how to call paintevent in function code to me ?

                                        jsulmJ 1 Reply Last reply
                                        0
                                        • M Mucahit

                                          Thank you sir, i know how i can make a watch. All i want is to call paintevent in readyread function and i couldn't solve this problem. All i want is a line of code not an article, i can't. Please can you share how to call paintevent in function code to me ?

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

                                          @Mucahit said in How to exit void QIODevice::readyRead() function ? Is this function also interrupt?:

                                          Please can you share how to call paintevent in function code to me ?

                                          This already was explained: you do NOT call paintEvent directly, Qt framework does it for you when the widget needs to be repainted. You call update() to trigger a paint event when needed.
                                          "All i want is a line of code not an article" - so, you want a magical line of code without spending time to learn how to paint? You already spent one day in forum. You could have read the example in this time to understand how it works...

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

                                          1 Reply Last reply
                                          2

                                          • Login

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