QCombobox slows my application
-
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.
-
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... -
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!
-
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
-
I would do it this way:
- load about 50 items in combobox.
- listen on scroll bar change in combobox and when it reaches end (or is near to it) load another 50 elements
- 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 :) -
Drax yours steps is called "lazy load"...
The second way is interesting...[quote author="DRAX" date="1355143829"]I would do it this way:
- load about 50 items in combobox.
- listen on scroll bar change in combobox and when it reaches end (or is near to it) load another 50 elements
- 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] -
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:
- load about 50 items in combobox.
- listen on scroll bar change in combobox and when it reaches end (or is near to it) load another 50 elements
- 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]
-
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!
-
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.
-
Have You tried
AdjustToMinimumContentsLengthWithIcon
or betterAdjustToMinimumContentsLength
inQCombobox::setSizeAdjustPolicy ( SizeAdjustPolicy policy )
?