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. QJsonArray deserialize and serialize
Forum Updated to NodeBB v4.3 + New Features

QJsonArray deserialize and serialize

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 738 Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Kris Revi
    wrote on last edited by Kris Revi
    #1

    Qt Side:

    void paintPixel(int row, int Col, uint16_t Color);
    
    connect(button, &QPushButton::clicked, [=]() { MainWindow::paintPixel(r, c, 0x0000); });
    
    void MainWindow::paintPixel(int Row, int Col, uint16_t Color)
    {
        qDebug() << "Row :" << Row << "Column :" << Col << "Pixel Color:" << Color;
    
        QJsonArray pixelInfo;
        pixelInfo.append(Row);
        pixelInfo.append(Col);
        pixelInfo.append(Color);
    
        socket.sendCommandStrip(QString("pixelPainter"), pixelInfo);
    }
    

    ESP32 Side

        if (doc["pixelPainter"]) {
          JsonArray src = doc["pixelPainter"].as<JsonArray>();
          const int Row = src[0];
          const int Col = src[1];
          const uint16_t color = src[2];
          Serial.println(Row);
          Serial.println(Col);
          Serial.println(color);
    
          display.drawPixel(Row, Col, color);
    
        }
    

    output from ESP32 is

    15  // Row is OK
    16  // Col is OK
    0   // This is wrong :S i only get 0 when it should be 0x0000
    

    what am i doing wrong?

    JonBJ 1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Kris-Revi said in QJsonArray deserialize and serialize:

      what am i doing wrong?

      nothing, 0 == 0x0000

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      K 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @Kris-Revi said in QJsonArray deserialize and serialize:

        what am i doing wrong?

        nothing, 0 == 0x0000

        K Offline
        K Offline
        Kris Revi
        wrote on last edited by
        #3

        @Christian-Ehrlicher but i need it to be 16bit format 0x0000 only color code the Matrix understands!

        Christian EhrlicherC 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Then convert the color information to a string. This is a special case, therefore you need to handle it appropriately.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • K Kris Revi

            @Christian-Ehrlicher but i need it to be 16bit format 0x0000 only color code the Matrix understands!

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Kris-Revi said in QJsonArray deserialize and serialize:

            only color code the Matrix understands!

            When you want a string, create a string or pass a string and not a number.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • K Offline
              K Offline
              Kris Revi
              wrote on last edited by
              #6

              @SGaist said in QJsonArray deserialize and serialize:

              Hi,
              Then convert the color information to a string. This is a special case, therefore you need to handle it appropriately.

              @Christian-Ehrlicher said in QJsonArray deserialize and serialize:

              @Kris-Revi said in QJsonArray deserialize and serialize:

              only color code the Matrix understands!

              When you want a string, create a string or pass a string and not a number.

                  if (doc["pixelPainter"]) {
                    //JsonObject object = doc["pixelPainter"].as<JsonObject>();
                    JsonArray src = doc["pixelPainter"].as<JsonArray>();
                    const int Row = src[0];
                    const int Col = src[1];
                    const String color = src[2];
                    Serial.println(Row);
                    Serial.println(Col);
                    Serial.println(color);
              
                    //display.clearDisplay();
                    display.drawPixel(Row, Col, color);
              
                  }
              

              Error:
              no suitable conversion function from "const String" to "uint16_t" exists
              no matching function for call to 'PxMATRIX::drawPixel(const int&, const int&, const String&)'

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Kris-Revi said in QJsonArray deserialize and serialize:

                no matching function for call to 'PxMATRIX::drawPixel(const int&, const int&, const String&)'

                so actually you need to pass an integer so why to you insist that you need to pass a string formatted as '0x0000' then??

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                K 1 Reply Last reply
                1
                • Christian EhrlicherC Christian Ehrlicher

                  @Kris-Revi said in QJsonArray deserialize and serialize:

                  no matching function for call to 'PxMATRIX::drawPixel(const int&, const int&, const String&)'

                  so actually you need to pass an integer so why to you insist that you need to pass a string formatted as '0x0000' then??

                  K Offline
                  K Offline
                  Kris Revi
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher cause the Matrix library only takes 16bit RGB ! so i need to feed it "0x0000"

                  Christian EhrlicherC JonBJ 2 Replies Last reply
                  0
                  • K Kris Revi

                    @Christian-Ehrlicher cause the Matrix library only takes 16bit RGB ! so i need to feed it "0x0000"

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Kris-Revi are you serious? Again: 0 = 0x000 = 0.0 = 0b000 = '\0' = ...

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    2
                    • K Kris Revi

                      @Christian-Ehrlicher cause the Matrix library only takes 16bit RGB ! so i need to feed it "0x0000"

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

                      @Kris-Revi
                      You are wrong, something is wrong in your understanding or reporting of the situation. Whatever your problem is (if there really is one), it is not as you are trying to express.

                      Please take the time to read back carefully through the replies above. You should understand the difference between a integer type and a string representation of an integer.

                      Since you show error message:
                      no suitable conversion function from "const String" to "uint16_t" exists

                      you know that the method accepts an integer and not a string. And once it's an integer 15, 16 or 0 are all integers, there is no "special" 0x0000.

                      1 Reply Last reply
                      2
                      • K Kris Revi

                        Qt Side:

                        void paintPixel(int row, int Col, uint16_t Color);
                        
                        connect(button, &QPushButton::clicked, [=]() { MainWindow::paintPixel(r, c, 0x0000); });
                        
                        void MainWindow::paintPixel(int Row, int Col, uint16_t Color)
                        {
                            qDebug() << "Row :" << Row << "Column :" << Col << "Pixel Color:" << Color;
                        
                            QJsonArray pixelInfo;
                            pixelInfo.append(Row);
                            pixelInfo.append(Col);
                            pixelInfo.append(Color);
                        
                            socket.sendCommandStrip(QString("pixelPainter"), pixelInfo);
                        }
                        

                        ESP32 Side

                            if (doc["pixelPainter"]) {
                              JsonArray src = doc["pixelPainter"].as<JsonArray>();
                              const int Row = src[0];
                              const int Col = src[1];
                              const uint16_t color = src[2];
                              Serial.println(Row);
                              Serial.println(Col);
                              Serial.println(color);
                        
                              display.drawPixel(Row, Col, color);
                        
                            }
                        

                        output from ESP32 is

                        15  // Row is OK
                        16  // Col is OK
                        0   // This is wrong :S i only get 0 when it should be 0x0000
                        

                        what am i doing wrong?

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

                        @Kris-Revi said in QJsonArray deserialize and serialize:

                        5  // Row is OK
                        16  // Col is OK
                        0   // This is wrong :S i only get 0 when it should be 0x0000
                        

                        Let's go back to this. I get it now. The third number is the 16-bit color value. It happens to have value 0 here. That should be OK. I think you are wrong in thinking it is wrong! it should be 0x0000 I think somewhere else you have seen the value of the color printed out as a 16-bit hex string. Where you go

                        Serial.println(color);
                        

                        in your code, don't you just mean you could change that to show the value in hex?

                        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