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

QTableWidget does not show values that come from a QMap

Scheduled Pinned Locked Moved Solved General and Desktop
qmapqtablewidget
3 Posts 2 Posters 681 Views
  • 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 1 Apr 2020, 14:55 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 1 Apr 2020, 15:13 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 1 Apr 2020, 17:27
      3
      • S SGaist
        1 Apr 2020, 15:13

        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 1 Apr 2020, 17:27 last edited by
        #3

        @SGaist Thank oyu, that worked!

        1 Reply Last reply
        0

        2/3

        1 Apr 2020, 15:13

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved