Update QSqlQueryModel for show new data entered or changued in a database table from another app



  • I have an object "QSqlQueryModel" to create a view that only displays a table data in sql server database 2005 but this table receives data from another app, then I need to know if there is any event or signal that allows the object "QSqlQueryModel" to update when new data is entered from the other app

    @
    ViFi::ViFi(QWidget *parent)
    : QWidget(parent)
    {

    CustomSqlModel *customModelAM = new CustomSqlModel;
    CustomSqlModel *customModelPM = new CustomSqlModel;
    initializeModel(customModelAM, customModelPM);
    
    QFont font12;
    font12.setPointSize(14);
    
    QHeaderView* headerViewAM = new QHeaderView(Qt::Horizontal);
    QHeaderView* headerViewPM = new QHeaderView(Qt::Horizontal);
    QFont* font = new QFont("Helvetica",20,10,true);
    headerViewAM->setFont(*font);
    headerViewAM->setResizeMode(QHeaderView::ResizeToContents);
    
    headerViewPM->setFont(*font);
    headerViewPM->setResizeMode(QHeaderView::ResizeToContents);
    
    _tableViewAM = new QTableView;
    _tableViewAM->setModel(customModelAM);      //MODEL 1
    _tableViewAM->setFont(font12);
    _tableViewAM->setHorizontalHeader(headerViewAM);
    _tableViewAM->resizeColumnsToContents();
    
    _tableViewPM = new QTableView;
    _tableViewPM->setModel(customModelPM);      //MODEL 2
    _tableViewPM->setFont(font12);
    _tableViewPM->setHorizontalHeader(headerViewPM);
    _tableViewPM->resizeColumnsToContents();
    
    createWidgets();
    setAttribute(Qt::WA_DeleteOnClose);
    

    }

    void ViFi::closeEvent(QCloseEvent *event)
    {
    event->accept();
    }

    void ViFi::initializeModel(QSqlQueryModel *modelAM, QSqlQueryModel *modelPM)
    {

    QString sqlqueryAM = QString("SELECT TOP 8 ....... ........");
    
    QString sqlqueryPM = QString("SELECT TOP 8  ............");
    

    qDebug() << sqlqueryAM;
    //MODEL1
    modelAM->setQuery(sqlqueryAM);
    modelAM->setHeaderData(0, Qt::Horizontal, tr("Date"));
    ...
    ...

    qDebug() << sqlqueryPM;
    //MODEL2
    modelPM->setQuery(sqlqueryPM);
    modelPM->setHeaderData(0, Qt::Horizontal, tr("Date"));
    ...
    ...
    }
    @

    Any suggestions?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.