Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved UI doesnt refresh correctly

    General and Desktop
    qt5 serial port user interface
    2
    20
    702
    Loading More Posts
    • 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.
    • D
      deleted286 @mrjj last edited by

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

      mrjj 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion @deleted286 last edited by mrjj

        @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 Reply Quote 0
        • D
          deleted286 @mrjj last edited by

          @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);
          
          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @deleted286 last edited by mrjj

            @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 Reply Quote 1
            • D
              deleted286 @mrjj last edited by

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

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @deleted286 last edited by

                @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 Reply Quote 1
                • D
                  deleted286 @mrjj last edited by

                  @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

                  mrjj 1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @deleted286 last edited by

                    @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 Reply Quote 0
                    • D
                      deleted286 @mrjj last edited by

                      This post is deleted!
                      mrjj 1 Reply Last reply Reply Quote 0
                      • mrjj
                        mrjj Lifetime Qt Champion @deleted286 last edited by

                        @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 Reply Quote 1
                        • D
                          deleted286 @mrjj last edited by

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

                          mrjj 1 Reply Last reply Reply Quote 0
                          • mrjj
                            mrjj Lifetime Qt Champion @deleted286 last edited by mrjj

                            @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 Reply Quote 0
                            • D
                              deleted286 @mrjj last edited by

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

                              mrjj 1 Reply Last reply Reply Quote 0
                              • mrjj
                                mrjj Lifetime Qt Champion @deleted286 last edited by mrjj

                                @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 Reply Quote 2
                                • D
                                  deleted286 @mrjj last edited by

                                  @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;
                                  
                                  mrjj 1 Reply Last reply Reply Quote 0
                                  • mrjj
                                    mrjj Lifetime Qt Champion @deleted286 last edited by

                                    @suslucoder

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

                                    D 1 Reply Last reply Reply Quote 0
                                    • D
                                      deleted286 @mrjj last edited by

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

                                      mrjj 1 Reply Last reply Reply Quote 0
                                      • mrjj
                                        mrjj Lifetime Qt Champion @deleted286 last edited by mrjj

                                        @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 Reply Quote 0
                                        • First post
                                          Last post