Results 1 to 10 of 10

Thread: Combobox Delegate 25.000 records

  1. #1
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Combobox Delegate 25.000 records

    Dear All

    I am having a problem with a combo box that I use in a tablewidget with a delegate. Combobox has the contents from a sql quary that has 25.000 lines of records. When I press the column in the table that has the combo, it takes nearly 10 sec to display the combo.

    Does any body could help for to make it faster!

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Combobox Delegate 25.000 records

    Quote Originally Posted by aekilic View Post
    Dear All
    Combobox has the contents from a sql quary that has 25.000 lines of records.
    Does any body could help for to make it faster!
    From mysql or sqlite?

    I have a 15000 contact mysql table if i run from from intranet the loading is 3-4 second
    if i copy on a ( therad process ) mysql table on a sqlite3 memory table it display on 1 second..

  3. #3
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Combobox Delegate 25.000 records

    I use postgres, but the solution could be help full, could you please tell me how you did it?

    I am a bit new to Qt...

  4. #4
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Combobox Delegate 25.000 records

    I write the network table to sqlite :memory: ram..

    Simply here a sample ....
    ad work on 2 connection cache & intranet

    Qt Code:
    1. /* open big database !!!! */
    2. /* i use sheme = "mysql://username:pass@host:port/database" */
    3. QUrl dns(sheme,QUrl::TolerantMode);
    4. const QString dbase = dns.path().replace("/","");
    5. QStringList drivers = QSqlDatabase::drivers();
    6. type = "Q"+dns.scheme().toUpper();
    7. std::cout << "######### type " << qPrintable(type ) << "\n" << std::endl;
    8. if (!drivers.contains(type)) {
    9. std::cout << "######### " << qPrintable(tr("Unable to Load Driver %1").arg(type)) << "\n" << std::endl;
    10. return false;
    11. }
    12. //// .....user port and so .............
    13. db = QSqlDatabase::addDatabase(type,QString("master_mysql_%1").arg(trac));
    14. /* open QSQLITE on ram */
    15. cachedb = QSqlDatabase::addDatabase("QSQLITE");
    16. cachedb.setDatabaseName(":memory:");
    17. if (!cachedb.open()) {
    18. QMessageBox::critical(0, qApp->tr("Cannot open local database"),
    19. qApp->tr("Unable to establish a cache database connection.\n\n"
    20. "Click Cancel to exit."), QMessageBox::Cancel);
    21. return false;
    22. }
    23.  
    24. LoadCache();
    25.  
    26. /* fill memory table to quick load and runn query */
    27. /* update i send to db mysql if needed relaod LoadCache() */
    28. void DB_Manager::LoadCache()
    29. {
    30. QSqlQuery query("",cachedb);
    31. QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    32. query.exec("DROP TABLE IF EXISTS catememo");
    33. query.exec("create table catememo (id INTEGER PRIMARY KEY AUTOINCREMENT,root_id INTEGER,name varchar(110),lft INTEGER,rgt INTEGER,oldid INTEGER,xmlattribute BLOB)");
    34. QStringList line_data;
    35. mod->setQuery(QString("SELECT * FROM %1 ").arg(TABELLA_CATES),current());
    36. const int summline = mod->rowCount();
    37.  
    38. for (int e = 0; e < summline; ++e) {
    39. line_data.clear();
    40. QSqlRecord r = mod->record(e);
    41. for (int x = 0; x < mod->columnCount(); ++x) {
    42. QString cellTxt = "'"+G_Quote(r.value(x).toString())+"'";
    43. line_data.append(cellTxt);
    44. }
    45. QString cainsert = QString("insert into catememo values (%1)").arg(line_data.join(","));
    46. bool mcis = query.exec(cainsert);
    47. }
    48.  
    49. QApplication::restoreOverrideCursor();
    50. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Combobox Delegate 25.000 records

    Should I have to write this to delegate?

    Second thing is first you disconnect with the current server and than you copy them to sqlite?

  6. #6
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Combobox Delegate 25.000 records

    Quote Originally Posted by aekilic View Post
    Should I have to write this to delegate?
    No, i have make a extra DBconnect manager to call other utility
    after first connect i fill cache...

    Second thing is first you disconnect with the current server and than you copy them to sqlite?
    If connection is open from server you can reload table any time...


    a extra DB manager i send instance to other widged or class to manage and fill combobox or export mysql dump ecc..


    here is a piece on dir
    http://ppk.ciz.ch/qt_c++/cms_layer/
    http://ppk.ciz.ch/qt_c++/cms_layer/DB_Manager.h
    http://ppk.ciz.ch/qt_c++/cms_layer/DB_Manager.cpp
    Last edited by patrik08; 24th May 2008 at 16:59.

  7. #7
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Combobox Delegate 25.000 records

    Hello everybody,

    I have connected 2 database for the program,

    Qt Code:
    1. db = QSqlDatabase::addDatabase("QPSQL");
    2. db.setHostName("10.0.0.11");
    3. db.setPort(5432);
    4. db.setDatabaseName(comboDonem->currentText());
    5. db.setUserName(lineKullanici->text());
    6. db.setPassword(lineSifre->text());
    To copy to clipboard, switch view to plain text mode 

    and the other one is

    Qt Code:
    1. QSqlDatabase::database("in_mem_db", false).close();
    2. QSqlDatabase::removeDatabase("in_mem_db");
    3. cachedb = QSqlDatabase::addDatabase("QSQLITE", "in_mem_db");
    4. cachedb.setDatabaseName(":memory:");
    5. if (!cachedb.open())
    6. {
    7. QMessageBox::warning(this, tr("Unable to open database"), tr("An error occured while opening the connection: ") + cachedb.lastError().text());
    8. return false;
    9. }
    To copy to clipboard, switch view to plain text mode 

    I could load the cache and select from cache. But the problem I have is when I go to another page(another .h file), I could not connect to cache. I could only connect db. (PQSQL)

    I want to know How could I connect the cache and select from there.

  8. #8
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Combobox Delegate 25.000 records

    simple point your cache connecion on query

    QSqlQuery query("",cachedb);

    like sql example

    connect / query to first db is
    QSqlQuery query();
    connect / query to sqlite memory
    QSqlQuery query("",cachedb);

    you can now query to all db listed on
    QStringList QSqlDatabase::connectionNames () [static]

    if you not like to save db pointer:

    QSqlDatabase QSqlDatabase::database ( const QString & connectionName = QLatin1String( defaultConnection ), bool open = true ) [static]

  9. #9
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Combobox Delegate 25.000 records

    Dear Patric

    Thank you for your reply again, but it didnt solve my problem actually.

    Should I have to connect to cachedb on main.cpp?

    Because what I do is on main cpp starts a entrance .ui which you log on the postgresql. In which i also connect to cachedb. After that you go to the mainpage.h. The problem I have is I could not connect to cache in the mainpage.h

  10. #10
    Join Date
    Jan 2007
    Posts
    201
    Thanks
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Combobox Delegate 25.000 records

    Dear Patric,

    I am trying mybest. But when I close the form that I created cachedb, and open another form, I lost connectiong to the cachedb. But default db connection(PQSQL) stays. Please help me...

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.