当前位置:网站首页>QT database realizes page turning function
QT database realizes page turning function
2022-06-12 14:19:00 【silence_ heart】
qt Use qsqltablemodel and tableview Control to operate and display the database , however qsqltablemodel Page flipping is not supported by itself .
however qsqltablemodel Of select Function will call selectStatement Statement returned by function , Query the database , That is, you can inherit qsqltablemodel class , Override the selectStatement Function to display a specific number of pages of data
Custom class mySqlTableModel Inherit qsqltablemodel
class mySqlTableModel : public QSqlTableModel
{
public:
mySqlTableModel();
QString selectStatement() const;
void totalRowCount();
void setSelectAllData(bool choose);
private:
int totalRows;
int currentPage;
bool selectAllData;
};
overwrite selectStatement function
QString mySqlTableModel::selectStatement()const{
QString strRet;
if(selectAllData){
return this->QSqlTableModel::selectStatement();
}else{
strRet+="select * from table_1 limit 5 offset "+QString::number((currentPage-1)*5);
}
return strRet;
}
Why add one selectAllData Variable , because QSqlTableModel Of filter The function will also use selectStatement function , To query the integrity of data , In the use of filter Function will selectAllData Assignment true , Use native selectStatement function
Statistics of the total number of rows
void mySqlTableModel::totalRowCount(){
QSqlQuery query;
query.exec("select * from table_1");
QSqlQueryModel *querymodel=new QSqlQueryModel();
querymodel->setQuery(query);
totalRows=querymodel->rowCount();
}
mySqlTableModel Page up and page down functions
// Page down
bool mySqlTableModel::pageDown(){
if(totalRows>currentPage*5){
currentPage++;
return true;
}
return false;
}
// Page up
bool mySqlTableModel::pageUp(){
if(currentPage>1){
currentPage--;
return true;
}
return false;
}
The main program uses mySqlTableModel Turn pages (model by mySqlTableModel Example )
// Page down
void MainWindow::on_pushButton_3_clicked()
{
model->pageDown();
model->setSelectAllData(false);
model->select();
}
// Page up
void MainWindow::on_pushButton_2_clicked()
{
model->pageUp();
model->setSelectAllData(false);
model->select();
}
边栏推荐
- Lua tvalue structure
- Player actual combat 25 unpacking module add close
- Solve the problem that IEEE latex template cannot display Chinese
- [MySQL advanced] index classification and index optimization scheme (V)
- C語言中主函數調用另外一個函數,匯編代碼理解
- C语言中主函数调用另外一个函数,汇编代码理解
- [advanced MySQL] evolution of MySQL index data structure (IV)
- Mold and remainder
- SystemC simulation scheduling mechanism
- 高考回憶錄
猜你喜欢
![[early knowledge of activities] list of recent activities of livevideostack](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[early knowledge of activities] list of recent activities of livevideostack

Alibaba cloud development board haas510 connects to the Internet of things platform -- Haas essay solicitation

高考回忆录

高考回憶錄

Player actual combat 13 create qtopengl project to promote window control and reload qoopenglwedge

Single bus temperature sensor 18B20 data on cloud (Alibaba cloud)

Player practice 17 xvideowidget

Redis data deletion policy in 2022

chrome://tracing Performance analysis artifact

对某热水软件的加密参数逆向
随机推荐
Summary of virtual box usage problems
[MySQL] basic database operation
对于跨境电商,更侧重收入的出价策略 —Google SEM
Redis core configuration and advanced data types
高考回憶錄
Crack WinRAR to ad pop-up window
Programmer interview golden classic good question / interview question 01.05 Edit once
For cross-border e-commerce, the bidding strategy focusing more on revenue - Google SEM
Axi4 increase burst / wrap burst/ fix burst and narrow transfer
En langage C, la fonction principale appelle une autre fonction et assemble le Code pour comprendre
Display logs in the database through loganalyzer
Analysis of two-dimensional array passing as function parameter (C language)
Analysis of lua source code
Player practice 19 xaudio turn on audio
Socket model of punctual atom stm32f429 core board
CSDN博客积分规则
How test engineers transform test and open
Now you must know the pointer
Implementation and debug of process hiding under x64
阿裏雲開發板HaaS510報送設備屬性