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. How to add rows automatically with sleep?

How to add rows automatically with sleep?

Scheduled Pinned Locked Moved Solved General and Desktop
tableviewqthreadsleep
3 Posts 2 Posters 656 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
    SoleyRan
    wrote on 24 Apr 2020, 08:40 last edited by
    #1

    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
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 24 Apr 2020, 08:45 last edited by
      #2

      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 26 Apr 2020, 15:18
      2
      • C Christian Ehrlicher
        24 Apr 2020, 08:45

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

        S Offline
        S Offline
        SoleyRan
        wrote on 26 Apr 2020, 15:18 last edited by
        #3

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

        1 Reply Last reply
        0

        1/3

        24 Apr 2020, 08:40

        • Login

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