Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTableWidget does not show values that come from a QMap



  • Hey guys,

    I have a QMap QMap<QString, float> sensorData; and I insert values like this:

    //these are just placeholders for my actual sensor values - these hardcoded values are just for testing now
    
        float acc_x = 0.5;
        float acc_y = 1.5;
        float acc_z = 2.5;
        float gyr_x = 3.5;
        float gyr_y =4.5;
        float gyr_z =5.5;
    
        sensorData =
        {
            {"acc_x", acc_x},
            {"acc_y", acc_y},
            {"acc_z", acc_z},
            {"gyr_x", gyr_x},
            {"gyr_y", gyr_y},
            {"gyr_z", gyr_z},
    
        };
    
    

    In my function (which receives the QMap via Signal/Slot), which is trying to print these values to a QWidgetTable I have:

        qDebug() << sensorData["acc_x"];
        ui->dataTable->setItem(0,0, new QTableWidgetItem(sensorData["acc_x"]));
        ui->dataTable->setItem(0,1, new QTableWidgetItem(sensorData["acc_y"]));
        ui->dataTable->setItem(0,2, new QTableWidgetItem(sensorData["acc_z"]));
        ui->dataTable->setItem(1,0, new QTableWidgetItem(sensorData["gyr_x"]));
        ui->dataTable->setItem(1,1, new QTableWidgetItem(sensorData["gyr_y"]));
        ui->dataTable->setItem(1,2, new QTableWidgetItem(sensorData["gyr_z"]));
    

    But the values are not shown in the table, the table is empty. But in the output console the correct value is printed for my
    qDebug() << sensorData["acc_x"]; so what might be wrong ?


  • Lifetime Qt Champion

    Hi,

    You are triggering this overload since you have a numerical value.

    Do an explicit conversion using QString::number.


  • Lifetime Qt Champion

    Hi,

    You are triggering this overload since you have a numerical value.

    Do an explicit conversion using QString::number.



  • @SGaist Thank oyu, that worked!


Log in to reply