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. QCombobox slows my application
Forum Updated to NodeBB v4.3 + New Features

QCombobox slows my application

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 4.3k 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.
  • R Offline
    R Offline
    ranger0
    wrote on last edited by
    #1

    Hello,

    I´m developping a database application which retrieve information for QComboBoxes via QSqlQueryModel.

    That´s a piece of my code:

    app.cpp
    @
    ...
    QSqlQueryModel * data = new QSqlQueryModel;
    data->setQuery("select data_information, data_code from data order by data_information");
    ui->combobox->setModel(data);
    ...
    @

    main.cpp
    @
    //headers
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    app * w = new app;
    w->show();

    return a.exec();
    

    }
    @

    I noticed that for large amount of data the steps:

    @
    w->show();
    return a.exec();
    @

    are taking a lot of time and making my application not to respond.

    When I replace the combobox to a QTableView the problem is solved.

    I really need my comboboxes, so does anyone know how to fix this problem?

    Thanks.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dcbasso
      wrote on last edited by
      #2

      Do you try to make the same thing using another code?
      I don't use this code as you show, I do the sql, return the QList<MyObject> and make a loop to add all itens in the QComboBox...

      For me works fine, and I have a lot of combobox in my app, and in same ui!
      I just don't have a lot of data to add to QComboBox...

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ranger0
        wrote on last edited by
        #3

        Hello,

        I tryed samething like that, and it makes my app even more slow.

        It seems that my problem is the amount of data.

        Actualy I don't have this huge set of data right now, but I'd like my application already prepared for this.

        Thanks for your suggestion!

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dcbasso
          wrote on last edited by
          #4

          I need to make a "lazy load" of this data...
          I don't now how but somewhere need to exists something that can help you...

          I need to load, for example, 10 items... when user gets at the tenth element you need to load more 10 elements... and you can make a lazy load...
          Or maybe using a resource that user can type the 3 first letters of what he needs (in combobox) and you can filter this amount of data... making something like this you can reduce the load of app, memory use and anyother things...

          Thanks

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DRAX
            wrote on last edited by
            #5

            I would do it this way:

            1. load about 50 items in combobox.
            2. listen on scroll bar change in combobox and when it reaches end (or is near to it) load another 50 elements
            3. keep doing untill all elements are loaded

            Another approach would be to load data in separated thread, and flush them to combobox when some amount of data is loaded (keep loading until all is loaded).
            I think this would be better but its up to you :)

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dcbasso
              wrote on last edited by
              #6

              Drax yours steps is called "lazy load"...
              The second way is interesting...

              [quote author="DRAX" date="1355143829"]I would do it this way:

              1. load about 50 items in combobox.
              2. listen on scroll bar change in combobox and when it reaches end (or is near to it) load another 50 elements
              3. keep doing untill all elements are loaded

              Another approach would be to load data in separated thread, and flush them to combobox when some amount of data is loaded (keep loading until all is loaded).
              I think this would be better as you can use application while collecting data.[/quote]

              1 Reply Last reply
              0
              • D Offline
                D Offline
                DRAX
                wrote on last edited by
                #7

                Thanks, I will keep it in mind :)

                [quote author="dcbasso" date="1355143959"]Drax yours steps is called "lazy load"...
                The second way is interesting...

                [quote author="DRAX" date="1355143829"]I would do it this way:

                1. load about 50 items in combobox.
                2. listen on scroll bar change in combobox and when it reaches end (or is near to it) load another 50 elements
                3. keep doing untill all elements are loaded

                Another approach would be to load data in separated thread, and flush them to combobox when some amount of data is loaded (keep loading until all is loaded).
                I think this would be better as you can use application while collecting data.[/quote]

                [/quote]

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  ranger0
                  wrote on last edited by
                  #8

                  Guys,

                  Thanks for your help!

                  But, as I told you before, the steps:

                  @
                  ...
                  w->show();
                  return a.exec();
                  ...
                  @

                  in main.cpp are too slow and I don't understand why.

                  The step:

                  @
                  ...
                  app * w = new app;
                  ...
                  @

                  which calls the constructor in which data is loaded, is much faster than that ones.

                  So, I don't think these solutions will work, but I'll try move the data loading to another thread and tell you what happens.

                  Thanks again!

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    ranger0
                    wrote on last edited by
                    #9

                    Hi,

                    I queued the data loading using signal/slot and it's better, but definitely combobox doesn't go well with large amount of data.

                    As I click to see the box, I have to wait same time to see the list.

                    I'll try to make my own completer which loads only the piece of data related with same text input.

                    Best regards.

                    1 Reply Last reply
                    0
                    • Aleksey_KA Offline
                      Aleksey_KA Offline
                      Aleksey_K
                      wrote on last edited by Aleksey_K
                      #10

                      Have You tried AdjustToMinimumContentsLengthWithIcon or better AdjustToMinimumContentsLength in QCombobox::setSizeAdjustPolicy ( SizeAdjustPolicy policy )?

                      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