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. [SOLVED] live update to qtablewidget not working
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] live update to qtablewidget not working

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.4k 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.
  • E Offline
    E Offline
    ecmanja
    wrote on last edited by
    #1

    hi, i'm trying to do live update of data to table for every 2 second delay. here is my code
    @
    QTableWidget *table=new QTableWidget(this);
    table->setGeometry(20,20,200,200);
    table->setRowCount(5);
    table->setColumnCount(1);
    int m=0,n=0;
    for(int i=0;i<5;i++)
    {
    table->setItem(m,n,new QTableWidgetItem("hello"));
    qDebug()<<" sleep for 2s ";
    sleep(2);
    m++;
    }
    @
    qdebug prints data for every 2 second delay but in qtablewidget ,data is not getting updated for every 2 second. table gets filled at a time after "for " loop ends.
    can anyone please tel me how to achieve this.

    thanks.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexisdm
      wrote on last edited by
      #2

      Hi,

      Any loop or blocking call (like sleep) in the main thread will prevent the GUI from updating itself.

      You could use a QTimer and a slot instead of a loop.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ecmanja
        wrote on last edited by
        #3

        alexisdm:: i tried using qtimer in slot function i need to update the qtablewidget continously with some delay but by using qtimer i can not see the table getting update.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alexisdm
          wrote on last edited by
          #4

          Without seeing the new code, I can't know what you might have done wrong.

          But basically, you should have something like:
          @table = new QTableWidget(this);
          table->setColumnCount(1);
          count = 5;
          timer = new QTimer(this);
          connect(timer, SIGNAL(timeout()), SLOT(updateSlot()));
          timer->start(2000);
          ...

          void YourClass::updateSlot()
          {
          Q_ASSERT(count>=0);
          --count;
          if(!count)
          timer->stop();
          int row = table->rowCount();
          table->insertRow(row);
          table->setItem(row, 0, new QTableWidgetItem("hello"));
          }
          @
          table, count and timer should all be members of the class so that they can be accessed in the slot.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ecmanja
            wrote on last edited by
            #5

            thanks alexisdm its working.

            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