[Solved] update the view

  • hello
    i have a qtableview witch display data from a database table by using qsqltablemodel when clicked on a row of this tableview another window open in this window i have a button when clicked this button the data of the database table is update when i close the window after updating i found that the view was not update i want that the view update
    please help me

  • Moderators

    Have you tried to call "select()":http://qt-project.org/doc/qt-5/qsqltablemodel.html#select on the model to update the view?

    Btw. Please use punctuation and capital letters where needed. It's really hard to read like that.

  • thank you chris kawa

    Sorry for my bad English
    so i have atable in may database called patient this
    i used qsqltable model like this
    ui.tableview.setmodal(true);@ to view the modal and every thing is going good
    iused the slot on table view clicked when users click on it a window open in this window i have a button that when user click on it the data of a spesific row of the table patient will be update
    when i close this window after updating i found that information don't update in the previous qtable view

  • Moderators

    Yes, try to call model.select() again, after you come back from the dialog.

    I didn't mean your english, I'm not a native speaker either. I meant separate your sentences with punctuation: ,.:; etc.

  • ok thank you
    but i don't understand how can i call it after i come back from th dialog
    Especially where?

  • Moderators

    There are couple of ways. For example in the closeEvent of your dialog you can emit a custom signal. connect() the select() slot of the model to that signal and you're done.

  • @void consultation::closeEvent(QCloseEvent *)

    // initialisation des cocher bilan
    QSqlQuery requete;
    requete.exec("UPDATE dictionnairebilan SET varplus=''");

    afficherRDV r;


    void afficherRDV::on_pushButton_2_clicked()

    // renouvelement de l'affichage normalement radha fonction
     QString numDP,nomPrenomDP;
      nomPrenomDP= ui->nomRchercherP ->text();
        if(numDP == "" && nomPrenomDP == "")
        QSqlQueryModel*model=new QSqlQueryModel();
        QSqlQuery *rr=new QSqlQuery();
        rr->exec("SELECT * FROM patient ");
        qDebug()<< "you are in the first part hhhh";
        else if( nomPrenomDP!=""  )
            const QString str1=ui->nomRchercherP->text();
            qDebug()<<str1<<"you are in the second part";
        else if( numDP!="")
            const QString str2=ui->nRechercherDP->text();
            qDebug()<<str2<<"you are in te third part";

    @ but it still the same broblem

  • Moderators

    This code doesn't look right.
    [quote author="yakine" date="1402765677"]r.ui->pushButton_2->clicked(true);[/quote]
    That's not how you emit a signal.

    Assuming you've got class SomeClass that has the model as member myModel and a second window SomeWidget as a member someWidget:

    Define a custom signal in the SomeWidget class and emit it from the close event:
    SomeWidget {
    void myCustomSignal();
    void closeEvent(QCloseEvent* evt) {
    emit myCustomSignal();
    In your SomeClass connect that signal to the model select() slot somewhere eg. in the constructor:
    SomeClass::SomeClass() {
    connect(someWidget, &SomeWidget::myCustomSignal, myModel, &QSqlTableModel::select);

  • thank you and sorry Chris kawa

    the problem it solved thank you again

Log in to reply

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