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. QTableWidget does not show values that come from a QMap
Servers for Qt installer are currently down

QTableWidget does not show values that come from a QMap

Scheduled Pinned Locked Moved Solved General and Desktop
qmapqtablewidget
3 Posts 2 Posters 721 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.
  • S Offline
    S Offline
    SpaceToon
    wrote on last edited by
    #1

    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 ?

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

      Hi,

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

      Do an explicit conversion using QString::number.

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

      S 1 Reply Last reply
      3
      • SGaistS SGaist

        Hi,

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

        Do an explicit conversion using QString::number.

        S Offline
        S Offline
        SpaceToon
        wrote on last edited by
        #3

        @SGaist Thank oyu, that worked!

        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