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. Qt - How to load data/process data after QWidget has been shown ?
Forum Updated to NodeBB v4.3 + New Features

Qt - How to load data/process data after QWidget has been shown ?

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

    HI ,
    When i am trying to load heavy data into a QTreeView, it is taking time to come up. Is there a way to do it after showing the QWidget?

    how to load widgets smoothly so that they don't have to wait for laoding all the data into them.

    Any help is appreciated

    Thanks

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p-himik
      wrote on last edited by
      #2

      You can try the Model-View way. As i know model fetches data only when needed.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Well, if you are loading data into a QTreeView you have to be already using the Model-View design pattern.

        A way (maybe not the best) to get what I guess you want, is creating a function in your project class where you could pass the Model pointer to QTreeView, to then call this function in the main.cpp (after *.show()).

        Something like this: lets say your project class is named "Test" and the function "showData", so:

        test.h:
        @
        class Test : public QMainWindow
        {

        Q_OBJECT
        

        public:

        explicit Test(QWidget *parent = 0);
        ~Test();
        
        ...
        
        void showData();
        
        ...
        

        };
        @

        test.cpp:
        @
        ...

        void Test::showData() {

        ui->treeView->setModel(&model);
        

        }

        ...
        @

        ... and then in your main.cpp, call showData() after w.show():

        main.cpp:
        @
        int main(int argc, char *argv[]) {

        QApplication a(argc, argv);

        Test w;

        w.show();

        w.showData();

        return a.exec();

        }
        @

        Another suggestion is to review the way about how you have implemented the load of your data, focused on performance.

        ...in this case this articles could help:

        "Performance Tip Optimizing Containers":http://developer.qt.nokia.com/wiki/Performance_Tip_Optimizing_Containers

        "Performance Tip Optimizing Iteration":http://developer.qt.nokia.com/wiki/Performance_Tip_Optimizing_Iteration

        "Iterating Efficiently":http://labs.qt.nokia.com/2009/01/23/iterating-efficiently/

        ...I hope this has been some way useful for you.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          veeeee_d
          wrote on last edited by
          #4

          Isn't all of that still freezing his application since the event loop processes clicking and painting events?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            Another option is to separate the model's code that gathers the data into a background process and to notify the model of the data dropping in. This it the way the [[Doc:QFileSystemModel]] works. Make sure to read the excellent article on "Threads, Events and QObjects":/wiki/Threads_Events_QObjects to avoid common problems and pitfalls.

            http://www.catb.org/~esr/faqs/smart-questions.html

            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