Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved How to add rows automatically with sleep?

    General and Desktop
    tableview qthread sleep
    2
    3
    400
    Loading More Posts
    • 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
      SoleyRan last edited by

      Hi everyone, I want to make my tableview to show rows automatically. The target is everytime the table shows 10 rows, then sleep 1s, then add 10 rows and continue...
      I used QThread::sleep(1) in my loop, but it would not show data until all data was loaded, but what I want is showing data while loading.
      My part code for testing this function is:

      QVector<QVector<QVariant>> d;
          for (int t = 1; t <= 10; t ++)
          {
              d.clear();
              for (int i = 0; i < 10; i++)
              {
                  QVector<QVariant> row;
                  row.clear();
                  for (int j = 0; j < 3; j++)
                      row.append(i*j*t);
                  d.append(row);
              }
              tablemodel->addData(d);      //addData is used to add all new data to model
              QThread::sleep(1);
          }
      

      Please help me. Thanks in advance! :)

      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        You're blokcing the event loop.
        Use a QTimer to add the rows later - whyever this should be needed at all.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        S 1 Reply Last reply Reply Quote 2
        • Christian Ehrlicher
          Christian Ehrlicher Lifetime Qt Champion last edited by

          You're blokcing the event loop.
          Use a QTimer to add the rows later - whyever this should be needed at all.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          S 1 Reply Last reply Reply Quote 2
          • S
            SoleyRan @Christian Ehrlicher last edited by

            @Christian-Ehrlicher Thank you very much! It solved my problem perfectly :)

            1 Reply Last reply Reply Quote 0
            • First post
              Last post