QJsonArray deserialize and serialize
-
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?
-
@Kris-Revi said in QJsonArray deserialize and serialize:
what am i doing wrong?
nothing, 0 == 0x0000
-
@Christian-Ehrlicher but i need it to be 16bit format
0x0000
only color code the Matrix understands! -
Hi,
Then convert the color information to a string. This is a special case, therefore you need to handle it appropriately.
-
@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.
-
@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&)'
-
@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??
-
@Christian-Ehrlicher cause the Matrix library only takes 16bit RGB ! so i need to feed it "0x0000"
-
@Kris-Revi are you serious? Again: 0 = 0x000 = 0.0 = 0b000 = '\0' = ...
-
@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
or0
are all integers, there is no "special"0x0000
. -
@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 goSerial.println(color);
in your code, don't you just mean you could change that to show the value in hex?