Home > Mobile > Program database operations, handle a lot of problems
Program database operations, handle a lot of problems
Time:10-07
hello, I want to ask you a question, help me use the QT platform, developed a relevant database program, the way is online see basic database operations, I wrote a first experiment program, there is no problem, have saved one million data, are all normal operation, then the code, I tested in my new program, there was a problem, In the Widget class, I add a callback function, if you receive send my hardware interrupts, first triggered the callback function, the callback function is a static nonmember functions, the callback function is triggered, will send events to the Widget class a member function of this member function of the Widget class, concrete action to save is to get the data, save the data code is my experiment before the database code, the whole program can be run normally, but there will be a big problem, is the program had been applying for many handle, as to save the amount of data, the greater the amount of handle more and more, in the end, the handle of the whole system has been used up, the system can't do anything, I saw the task manager, memory consumption, CPU also have no, is to handle in the increase of the crazy, programs run on Windows 7 system, operating system, directly prompt system resources exhausted, what all points not, finally can only restart the computer, Database operation part about logic is as follows:
QSqlDatabase database=QSqlDatabase: : addDatabase (" QSQLITE "); Database. SetDatabaseName (" VMIC_DataBase. Db "); The database transaction (); For (int I=0; I & lt; NUM. I++) { QString qsStr; QsStr. Sprintf (" insert into member values (' % s', % d) ", nDatabaseID, cRecBufAssem [I]); Bool success=query. The exec (qsStr); } if(! QSqlDatabase: : database (). The commit ()) { QDebug () & lt; if(! QSqlDatabase: : database (). The rollback ()) { QDebug () & lt; } }
through my screening, its consumption should handle is this: Bool success=query. The exec (qsStr); I want to ask you, why will appear this kind of circumstance, I before the experiment procedure, also have this statement, how no handle to consumption, how to solve this problem, how to apply for or to release handle, I am a novice, not skilled to QT, please answer, a little detail, thank you, thank you, online, etc.,
CodePudding user response:
Is usually the main function to perform database is opened, the last program close when database, instead of using the database every time opening and closing time! That need to use handle every time!