Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. UI doesnt refresh correctly

UI doesnt refresh correctly

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5serial portuser interface
20 Posts 2 Posters 2.4k 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 mrjj
    27 Feb 2021, 11:01

    Hi
    Im not sure what you want to use a timer for.
    You already have
    connect(serial, &QSerialPort::readyRead, this, &MainWindow::on_Serial_Read);

    so when data comes, Qt calls your on_Serial_Read

    Calling the on_joystick from a timer will not work good as
    it will be very out of sync with on_Serial_Read and data in "dizi"
    might not been read in yet.

    So if you see odd data , it would be that timer seems very fast and at
    the first calls, the "dizi" will not have valid values as on_Serial_Read didnt trigger yet.

    D Offline
    D Offline
    deleted286
    wrote on 27 Feb 2021, 11:05 last edited by
    #3

    @mrjj my progress bar was stuck on some point. It doesnt see the correct data. I doesnt refresh yourselft when new data comes

    M 1 Reply Last reply 27 Feb 2021, 11:25
    0
    • D deleted286
      27 Feb 2021, 11:05

      @mrjj my progress bar was stuck on some point. It doesnt see the correct data. I doesnt refresh yourselft when new data comes

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 27 Feb 2021, 11:25 last edited by mrjj
      #4

      @suslucoder
      Did you check the incoming data ?
      Its more likely some unexpected with the data than any refresh problem.

      In on_Serial_Read when dont you just call on_joystick ? ( i assume on_joystick is where you set the data to the GUI)

      D 1 Reply Last reply 27 Feb 2021, 11:40
      0
      • M mrjj
        27 Feb 2021, 11:25

        @suslucoder
        Did you check the incoming data ?
        Its more likely some unexpected with the data than any refresh problem.

        In on_Serial_Read when dont you just call on_joystick ? ( i assume on_joystick is where you set the data to the GUI)

        D Offline
        D Offline
        deleted286
        wrote on 27 Feb 2021, 11:40 last edited by
        #5

        @mrjj on serial read, im reading from serial and on_joystick i put the datas on my gui. Where should i call joystick

        connect(serial, &QSerialPort::readyRead, this, &MainWindow::on_Serial_Read);
                //connect(serial, &QSerialPort::readyRead, this, &MainWindow::on_joystick);
        
        M 1 Reply Last reply 27 Feb 2021, 11:51
        0
        • D deleted286
          27 Feb 2021, 11:40

          @mrjj on serial read, im reading from serial and on_joystick i put the datas on my gui. Where should i call joystick

          connect(serial, &QSerialPort::readyRead, this, &MainWindow::on_Serial_Read);
                  //connect(serial, &QSerialPort::readyRead, this, &MainWindow::on_joystick);
          
          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 27 Feb 2021, 11:51 last edited by mrjj
          #6

          @suslucoder
          hi
          at the very end of :on_Serial_Read()

          so get signal, read data and call on_joystick to display the 14 data you just copied to dizi

          D 1 Reply Last reply 27 Feb 2021, 12:11
          1
          • M mrjj
            27 Feb 2021, 11:51

            @suslucoder
            hi
            at the very end of :on_Serial_Read()

            so get signal, read data and call on_joystick to display the 14 data you just copied to dizi

            D Offline
            D Offline
            deleted286
            wrote on 27 Feb 2021, 12:11 last edited by
            #7

            @mrjj I did it like that. But i dont know why in some data, progress bar doesnt refresh.

            M 1 Reply Last reply 27 Feb 2021, 12:46
            0
            • D deleted286
              27 Feb 2021, 12:11

              @mrjj I did it like that. But i dont know why in some data, progress bar doesnt refresh.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 27 Feb 2021, 12:46 last edited by
              #8

              @suslucoder

              well if dont move the bar, the most logical conclusion is that it gets the same value as before.

              So put in
              qDebug() << "-->"<< dizi[1] << dizi[2]<< dizi[3]<< dizi[4]<< dizi[5]<< dizi[6];
              in on_joystick (in top)
              and see when it dont move what data, if it still has the same value as before.

              D 1 Reply Last reply 1 Mar 2021, 06:03
              1
              • M mrjj
                27 Feb 2021, 12:46

                @suslucoder

                well if dont move the bar, the most logical conclusion is that it gets the same value as before.

                So put in
                qDebug() << "-->"<< dizi[1] << dizi[2]<< dizi[3]<< dizi[4]<< dizi[5]<< dizi[6];
                in on_joystick (in top)
                and see when it dont move what data, if it still has the same value as before.

                D Offline
                D Offline
                deleted286
                wrote on 1 Mar 2021, 06:03 last edited by
                #9

                @mrjj said in UI doesnt refresh correctly:

                qDebug() << "-->"<< dizi[1] << dizi[2]<< dizi[3]<< dizi[4]<< dizi[5]<< dizi[6];

                I've checked, coming datas are true. Is there anything about threads? I have serial port and i have a gui. There may be something different about it

                M 1 Reply Last reply 1 Mar 2021, 06:35
                0
                • D deleted286
                  1 Mar 2021, 06:03

                  @mrjj said in UI doesnt refresh correctly:

                  qDebug() << "-->"<< dizi[1] << dizi[2]<< dizi[3]<< dizi[4]<< dizi[5]<< dizi[6];

                  I've checked, coming datas are true. Is there anything about threads? I have serial port and i have a gui. There may be something different about it

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 1 Mar 2021, 06:35 last edited by
                  #10

                  @suslucoder
                  Hi
                  Only if you added threads yourself. else it cant be the issue.

                  So that data is right in top of on_joystick ?
                  that you are very sure about ?

                  Since we dont clear dizi between readyRead
                  it will have old values.

                  So waht excactly do you see ?
                  first it work, then it stops. or it never works ?

                  D 1 Reply Last reply 1 Mar 2021, 06:42
                  0
                  • M mrjj
                    1 Mar 2021, 06:35

                    @suslucoder
                    Hi
                    Only if you added threads yourself. else it cant be the issue.

                    So that data is right in top of on_joystick ?
                    that you are very sure about ?

                    Since we dont clear dizi between readyRead
                    it will have old values.

                    So waht excactly do you see ?
                    first it work, then it stops. or it never works ?

                    D Offline
                    D Offline
                    deleted286
                    wrote on 1 Mar 2021, 06:42 last edited by
                    #11
                    This post is deleted!
                    M 1 Reply Last reply 1 Mar 2021, 06:48
                    0
                    • D deleted286
                      1 Mar 2021, 06:42

                      This post is deleted!

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 1 Mar 2021, 06:48 last edited by
                      #12

                      @suslucoder
                      Well it cant really be stuck as such.
                      It means its current value is 15.

                      You dont have any loops or anything that would prevent it from redrawing ?

                      I think you will have to use the debugger and set breakpoint on the

                      ui->progressBarXXXX

                      and then see when you set data what it is.

                      Its very unlikely the Widget simply don't redraw as that normally makes them white/odd if
                      you have strangulated the event loop.

                      D 1 Reply Last reply 1 Mar 2021, 07:54
                      1
                      • M mrjj
                        1 Mar 2021, 06:48

                        @suslucoder
                        Well it cant really be stuck as such.
                        It means its current value is 15.

                        You dont have any loops or anything that would prevent it from redrawing ?

                        I think you will have to use the debugger and set breakpoint on the

                        ui->progressBarXXXX

                        and then see when you set data what it is.

                        Its very unlikely the Widget simply don't redraw as that normally makes them white/odd if
                        you have strangulated the event loop.

                        D Offline
                        D Offline
                        deleted286
                        wrote on 1 Mar 2021, 07:54 last edited by
                        #13

                        @mrjj I didnt understand what you mean. Am i doing something wrong?

                        M 1 Reply Last reply 1 Mar 2021, 08:10
                        0
                        • D deleted286
                          1 Mar 2021, 07:54

                          @mrjj I didnt understand what you mean. Am i doing something wrong?

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 1 Mar 2021, 08:10 last edited by mrjj 3 Jan 2021, 08:17
                          #14

                          @suslucoder
                          Hi
                          Nope code looks fine but you seem think the widget would suddenly stop to draw and
                          they rarely do and if they do, then it's very clear as it then looked messed up.

                          So Im trying to guess at what could be wrong/go wrong.
                          I think its just something with the data but you seems sure the values are newer and higher than 15 so
                          I would like you to set a break point on the line where you set the progressbar value
                          and then run & stop and inspect value in the dubugger to be truely sure that a value higher than 15 comes.

                          other note, this line
                          memcpy(dizi, data.constData(), 14);

                          If less than 14 data comes, then old values are left in dizi.
                          and what happens if data.constData() is less than 14 ?

                          I think its something like that.

                          D 1 Reply Last reply 1 Mar 2021, 08:18
                          0
                          • M mrjj
                            1 Mar 2021, 08:10

                            @suslucoder
                            Hi
                            Nope code looks fine but you seem think the widget would suddenly stop to draw and
                            they rarely do and if they do, then it's very clear as it then looked messed up.

                            So Im trying to guess at what could be wrong/go wrong.
                            I think its just something with the data but you seems sure the values are newer and higher than 15 so
                            I would like you to set a break point on the line where you set the progressbar value
                            and then run & stop and inspect value in the dubugger to be truely sure that a value higher than 15 comes.

                            other note, this line
                            memcpy(dizi, data.constData(), 14);

                            If less than 14 data comes, then old values are left in dizi.
                            and what happens if data.constData() is less than 14 ?

                            I think its something like that.

                            D Offline
                            D Offline
                            deleted286
                            wrote on 1 Mar 2021, 08:18 last edited by
                            #15

                            @mrjj data.constData() cant be less than 14. I set it. Its too weird

                            M 1 Reply Last reply 1 Mar 2021, 08:31
                            0
                            • D deleted286
                              1 Mar 2021, 08:18

                              @mrjj data.constData() cant be less than 14. I set it. Its too weird

                              M Offline
                              M Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on 1 Mar 2021, 08:31 last edited by mrjj 3 Jan 2021, 08:31
                              #16

                              @suslucoder
                              Hi
                              What you mean ?
                              You dont set it at all

                              QByteArray data = serial->readAll(); <<< this can read all from 1 to xxx bytes

                              s= data.size(); << this is the size of data we read
                              if (s>14)  << is is just some variable not related to data
                                  s=14;
                              

                              then we copy 14 from data
                              memcpy(dizi, data.constData(), 14);

                              so it dont matter how much data we actually got. we always copy 14

                              D 1 Reply Last reply 1 Mar 2021, 08:36
                              2
                              • M mrjj
                                1 Mar 2021, 08:31

                                @suslucoder
                                Hi
                                What you mean ?
                                You dont set it at all

                                QByteArray data = serial->readAll(); <<< this can read all from 1 to xxx bytes

                                s= data.size(); << this is the size of data we read
                                if (s>14)  << is is just some variable not related to data
                                    s=14;
                                

                                then we copy 14 from data
                                memcpy(dizi, data.constData(), 14);

                                so it dont matter how much data we actually got. we always copy 14

                                D Offline
                                D Offline
                                deleted286
                                wrote on 1 Mar 2021, 08:36 last edited by
                                #17

                                @mrjj said in UI doesnt refresh correctly:

                                @suslucoder
                                Hi
                                What you mean ?

                                I have

                                int16_t dizi[7];
                                

                                Since I have an array which size is 7, i wrote something

                                s= data.size(); 
                                if (s>14)  
                                    s=14;
                                
                                M 1 Reply Last reply 1 Mar 2021, 08:37
                                0
                                • D deleted286
                                  1 Mar 2021, 08:36

                                  @mrjj said in UI doesnt refresh correctly:

                                  @suslucoder
                                  Hi
                                  What you mean ?

                                  I have

                                  int16_t dizi[7];
                                  

                                  Since I have an array which size is 7, i wrote something

                                  s= data.size(); 
                                  if (s>14)  
                                      s=14;
                                  
                                  M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 1 Mar 2021, 08:37 last edited by
                                  #18

                                  @suslucoder

                                  But what do you then do with s to make it do anything ?

                                  D 1 Reply Last reply 1 Mar 2021, 08:40
                                  0
                                  • M mrjj
                                    1 Mar 2021, 08:37

                                    @suslucoder

                                    But what do you then do with s to make it do anything ?

                                    D Offline
                                    D Offline
                                    deleted286
                                    wrote on 1 Mar 2021, 08:40 last edited by
                                    #19

                                    @mrjj Im just try to convert my binary data do int with that code script

                                    M 1 Reply Last reply 1 Mar 2021, 08:42
                                    0
                                    • D deleted286
                                      1 Mar 2021, 08:40

                                      @mrjj Im just try to convert my binary data do int with that code script

                                      M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 1 Mar 2021, 08:42 last edited by mrjj 3 Jan 2021, 08:43
                                      #20

                                      @suslucoder

                                      ok im not sure what s does.

                                      Anyway, could you try

                                      (in on_Serial_Read)
                                      memset(dizi, 0, 14);
                                      memcpy(dizi, data.constData(), data.size());

                                      in place ot the line
                                      memcpy(dizi, data.constData(), 14);

                                      and tell if it still stops at 15 ?

                                      1 Reply Last reply
                                      0

                                      12/20

                                      1 Mar 2021, 06:48

                                      • Login

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