Page 2 of 2 FirstFirst 12
Results 21 to 35 of 35

Thread: Big Problem search through huge amount of data ca 30 000 strings takes to long

  1. #21
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Yes I did a search that shows me only items or so. With only 1 character in the searchlines i have thousands of items and that takes minutes.
    If I remove processevents I have an unresponsive GUI, makes no sense.

    I can make a small Project that illustrates the problem, maybe then its much clearer. I see at some comments that its not very clear what it does. I do that in a few hours.

  2. #22
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Show code for listWidget_addItemPlusTooltip() method.

  3. #23
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Quote Originally Posted by Ini View Post
    I don't see the point of the timer, but nvm here is the data:
    It is to verify that the filtering itself is not the problem.
    As the data nicely demonstrates it is always done in less than 100ms.

    Quote Originally Posted by Ini View Post
    Its as expected first loop always constant and second loop depends on what i typed in. If I type in only 1 character second loop takes like 3 minutes or so
    That's because then you have thousands of items that match.
    The more matches, the longer it takes to create all these list widget items.

    Quote Originally Posted by Ini View Post
    I dont understand why should nobody see them.
    I didn't know you had a magical screen with nearly unlimited screen space.
    Usually a list only shows tens of items.

    But even if your list widget really shows all 30000 items at the same time, creating list widget items is still more wasteful than using a model.

    Quote Originally Posted by Ini View Post
    Thank you for all help, but the hate stuff is not very helpfull
    It is my only explanation why you would like to continue to suffer.
    If you are not trying to punish yourself are you Trying to win a bet?

    Quote Originally Posted by Ini View Post
    And thats true what you say it would be faster to store the previous data. But that does not solve the problem.
    Hence this being an additional, secondary, improvement suggestion.

    Cheers,
    _

  4. #24
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    "I didn't know you had a magical screen with nearly unlimited screen space.
    Usually a list only shows tens of items.

    But even if your list widget really shows all 30000 items at the same time, creating list widget items is still more wasteful than using a model."

    The Listwidget has a Scrollbar.
    Why is a Model faster?

    "Show code for listWidget_addItemPlusTooltip() method. "

    inline void listWidget_addItemPlusTooltip(QListWidget* paramListWidget,QString paramText)
    {
    paramListWidget->addItem(paramText);
    paramListWidget->item(paramListWidget->count()-1)->setToolTip(paramText);
    }

  5. #25
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Quote Originally Posted by Ini View Post
    The Listwidget has a Scrollbar.
    If it has a scrollbar then this usually means not all items are visible.
    Do you have a list that can show all 30000 items without scrolling or do you have a limit on how many items can be shown at any given time?

    Quote Originally Posted by Ini View Post
    Why is a Model faster?
    Even in you case with the giant screen that can show all 30000 items at the same time, it wouldn't have to create QListViewItem instances.
    In a normal case, when the screen size does not allow to show 30000 list items at the same time, it becomes even better, since the view only needs to deal with data for entries that it shows.

    But even in your case, with your list view showing actually all 30000 items at once, it should be faster.

    Cheers,
    _

  6. #26
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Why every time You create the paramListWidget from scratch ?
    Is it not enough to do show / hide on the elements of the Storage::identifier list ?

  7. #27
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9.  
    10. ui->identifier_progressBar->setVisible(false);
    11.  
    12. for (int i = 0; i < 10000; i++) {
    13. list << QString("test"+QString::number(i));
    14. ui->identifier_listWidget->addItem(list.at(i));
    15. }
    16.  
    17. connect(ui->identifier_lineEdit_search_0,SIGNAL(textChanged(QString)),this,SLOT(searchIn_identifier_listWidget()));
    18. connect(ui->identifier_lineEdit_search_1,SIGNAL(textChanged(QString)),this,SLOT(searchIn_identifier_listWidget()));
    19. connect(ui->identifier_lineEdit_search_2,SIGNAL(textChanged(QString)),this,SLOT(searchIn_identifier_listWidget()));
    20. connect(ui->identifier_lineEdit_search_3,SIGNAL(textChanged(QString)),this,SLOT(searchIn_identifier_listWidget()));
    21. connect(ui->identifier_lineEdit_search_4,SIGNAL(textChanged(QString)),this,SLOT(searchIn_identifier_listWidget()));
    22. }
    23.  
    24. MainWindow::~MainWindow()
    25. {
    26. delete ui;
    27. }
    28.  
    29. void MainWindow::searchIn_identifier_listWidget()
    30. {
    31. searchIn_identifier_listWidget_eventLoopControl = false;
    32.  
    33. QList<QString> tempList;
    34. int max = 0;
    35.  
    36. QString text0 = ui->identifier_lineEdit_search_0->text();
    37. QString text1 = ui->identifier_lineEdit_search_1->text();
    38. QString text2 = ui->identifier_lineEdit_search_2->text();
    39. QString text3 = ui->identifier_lineEdit_search_3->text();
    40. QString text4 = ui->identifier_lineEdit_search_4->text();
    41.  
    42. for (int i = 0; i < list.count(); i++) {
    43. qApp->processEvents();
    44. if (searchIn_identifier_listWidget_eventLoopControl) {
    45. return;
    46. }
    47. if (list.at(i).contains(text0,Qt::CaseInsensitive) &&
    48. list.at(i).contains(text1,Qt::CaseInsensitive) &&
    49. list.at(i).contains(text2,Qt::CaseInsensitive) &&
    50. list.at(i).contains(text3,Qt::CaseInsensitive) &&
    51. list.at(i).contains(text4,Qt::CaseInsensitive))
    52. {
    53. tempList << list.at(i);
    54. }
    55. }
    56.  
    57. ui->identifier_progressBar->setVisible(true);
    58. ui->identifier_listWidget->clear();
    59. ui->identifier_progressBar->setValue(0);
    60. max = tempList.count();
    61. ui->identifier_progressBar->setMaximum(max-1);
    62. for (int i = 0; i < max; i++) {
    63. qApp->processEvents();
    64. if (searchIn_identifier_listWidget_eventLoopControl) {
    65. return;
    66. }
    67. ui->identifier_listWidget->addItem(tempList.at(i));
    68. ui->identifier_progressBar->setValue(i);
    69. }
    70. ui->identifier_progressBar->setVisible(false);
    71.  
    72. searchIn_identifier_listWidget_eventLoopControl = true;
    73. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class MainWindow;
    8. }
    9.  
    10. class MainWindow : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17.  
    18. QList<QString> list;
    19. bool searchIn_identifier_listWidget_eventLoopControl = false;
    20.  
    21. private:
    22. Ui::MainWindow *ui;
    23.  
    24. private slots:
    25. void searchIn_identifier_listWidget();
    26. };
    27.  
    28. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 


    This is how it works and should work. But code is so ugly. I would need a different solution to the nested events.

    edit: AHHH WAIT i need to add GUI code

    edit: heres the GUI code, idk if its OK like this if not I upload the project somewhere. Is it ok like this?

    mainwindow.ui
    Qt Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>MainWindow</class>
    4. <widget class="QMainWindow" name="MainWindow">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>809</width>
    10. <height>768</height>
    11. </rect>
    12. </property>
    13. <property name="windowTitle">
    14. <string>MainWindow</string>
    15. </property>
    16. <widget class="QWidget" name="centralWidget">
    17. <widget class="QListWidget" name="identifier_listWidget">
    18. <property name="geometry">
    19. <rect>
    20. <x>40</x>
    21. <y>310</y>
    22. <width>541</width>
    23. <height>261</height>
    24. </rect>
    25. </property>
    26. </widget>
    27. <widget class="QLineEdit" name="identifier_lineEdit_search_4">
    28. <property name="geometry">
    29. <rect>
    30. <x>40</x>
    31. <y>230</y>
    32. <width>541</width>
    33. <height>31</height>
    34. </rect>
    35. </property>
    36. <property name="placeholderText">
    37. <string>Search</string>
    38. </property>
    39. </widget>
    40. <widget class="QLineEdit" name="identifier_lineEdit_search_3">
    41. <property name="geometry">
    42. <rect>
    43. <x>40</x>
    44. <y>190</y>
    45. <width>541</width>
    46. <height>31</height>
    47. </rect>
    48. </property>
    49. <property name="placeholderText">
    50. <string>Search</string>
    51. </property>
    52. </widget>
    53. <widget class="QPushButton" name="identifier_pushButton_clear_search">
    54. <property name="geometry">
    55. <rect>
    56. <x>40</x>
    57. <y>270</y>
    58. <width>541</width>
    59. <height>31</height>
    60. </rect>
    61. </property>
    62. <property name="text">
    63. <string>Clear search</string>
    64. </property>
    65. </widget>
    66. <widget class="QProgressBar" name="identifier_progressBar">
    67. <property name="geometry">
    68. <rect>
    69. <x>40</x>
    70. <y>30</y>
    71. <width>541</width>
    72. <height>23</height>
    73. </rect>
    74. </property>
    75. <property name="value">
    76. <number>24</number>
    77. </property>
    78. </widget>
    79. <widget class="QLineEdit" name="identifier_lineEdit_search_0">
    80. <property name="geometry">
    81. <rect>
    82. <x>40</x>
    83. <y>70</y>
    84. <width>541</width>
    85. <height>31</height>
    86. </rect>
    87. </property>
    88. <property name="placeholderText">
    89. <string>Search</string>
    90. </property>
    91. </widget>
    92. <widget class="QLineEdit" name="identifier_lineEdit_search_1">
    93. <property name="geometry">
    94. <rect>
    95. <x>40</x>
    96. <y>110</y>
    97. <width>541</width>
    98. <height>31</height>
    99. </rect>
    100. </property>
    101. <property name="placeholderText">
    102. <string>Search</string>
    103. </property>
    104. </widget>
    105. <widget class="QLineEdit" name="identifier_lineEdit_search_2">
    106. <property name="geometry">
    107. <rect>
    108. <x>40</x>
    109. <y>150</y>
    110. <width>541</width>
    111. <height>31</height>
    112. </rect>
    113. </property>
    114. <property name="placeholderText">
    115. <string>Search</string>
    116. </property>
    117. </widget>
    118. </widget>
    119. <widget class="QMenuBar" name="menuBar">
    120. <property name="geometry">
    121. <rect>
    122. <x>0</x>
    123. <y>0</y>
    124. <width>809</width>
    125. <height>21</height>
    126. </rect>
    127. </property>
    128. </widget>
    129. <widget class="QToolBar" name="mainToolBar">
    130. <attribute name="toolBarArea">
    131. <enum>TopToolBarArea</enum>
    132. </attribute>
    133. <attribute name="toolBarBreak">
    134. <bool>false</bool>
    135. </attribute>
    136. </widget>
    137. <widget class="QStatusBar" name="statusBar"/>
    138. </widget>
    139. <layoutdefault spacing="6" margin="11"/>
    140. <resources/>
    141. <connections/>
    142. </ui>
    To copy to clipboard, switch view to plain text mode 
    Last edited by anda_skoa; 21st March 2016 at 16:59. Reason: changed [quote] to [code]

  8. #28
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Quote Originally Posted by Lesiok View Post
    Why every time You create the paramListWidget from scratch ?
    Ini doesn't like simple solutions, probably working for a company that punishes people for easy to maintain code.

    Quote Originally Posted by Lesiok View Post
    Is it not enough to do show / hide on the elements of the Storage::identifier list ?
    That might work, as it fullfills the requirement of making the search result faster and the requirement of involving lots of code with loops.

    Cheers,
    _

  9. #29
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    sry but not helpful. try a solution with hide and you see it works much worse/slower.

    if not upload it pls instead of fooling me


    Added after 18 minutes:


    how can it be possible to show a result after every character typed in without an nested event. I know no solution. Its not requirement to make it faster requirement is to make code more beatiful
    Last edited by Ini; 21st March 2016 at 18:07.

  10. #30
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    I'll let Lesiok handle that since you are ignoring my advice anyway.

    Cheers,
    _

  11. #31
    Join Date
    Nov 2015
    Posts
    67

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    no I do not I work on the problem and not insert code that just speed it up my few ms. I can do that later

  12. #32
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Quote Originally Posted by Ini View Post
    no I do not I work on the problem and not insert code that just speed it up my few ms. I can do that later
    Ok, if you don't want Lesiok's help to speed up things either, then I guess you'll have to wait for someone new that you can then ignore.
    Good luck with that.

    Cheers,
    _

  13. #33
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    QListWidget has such a cool method QListWidget::insertItems.

  14. #34
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    Regarding search and waiting for the results,

    Your algorithm is naive and far away from being optimal. It would be much better to preprocess the original data into some kind of prefix tree and search that tree instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #35
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Big Problem search through huge amount of data ca 30 000 strings takes to long

    @wysota - I'm afraid you don't understand. The OP doesn't want a better solution that works faster. He wants his current solution to work faster without changing anything about what he's written.

Similar Threads

  1. Replies: 9
    Last Post: 29th March 2011, 09:55
  2. QTextEdit loading takes long time
    By sreedhar in forum Qt Programming
    Replies: 12
    Last Post: 21st March 2011, 10:29
  3. Problem: the Application Takes very long time to build
    By Ma7moud El-Naggar in forum Qt Programming
    Replies: 5
    Last Post: 20th November 2010, 06:26
  4. [QTableWidget] clearing a big table takes so long!
    By punkypogo in forum Qt Programming
    Replies: 4
    Last Post: 5th August 2010, 13:52
  5. QImage::scaled takes long time
    By nrabara in forum Qt Programming
    Replies: 0
    Last Post: 15th December 2009, 12:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.