Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    [Solved] update the view

    General and Desktop
    2
    9
    1743
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Y
      yakine last edited by

      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

      IF YOU HAVE MERCY ON PEOPLE GOD HAVE MERCY ON YOU

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • Y
          yakine last edited by

          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
          @model.settable("patient");
          model.select();
          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

          IF YOU HAVE MERCY ON PEOPLE GOD HAVE MERCY ON YOU

          1 Reply Last reply Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • Y
              yakine last edited by

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

              IF YOU HAVE MERCY ON PEOPLE GOD HAVE MERCY ON YOU

              1 Reply Last reply Reply Quote 0
              • Chris Kawa
                Chris Kawa Moderators last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • Y
                  yakine last edited by

                  @void consultation::closeEvent(QCloseEvent *)
                  {

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

                  afficherRDV r;
                  r.ui->pushButton_2->clicked(true);

                  }

                  void afficherRDV::on_pushButton_2_clicked()
                  {

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

                  }
                  @ but it still the same broblem

                  IF YOU HAVE MERCY ON PEOPLE GOD HAVE MERCY ON YOU

                  1 Reply Last reply Reply Quote 0
                  • Chris Kawa
                    Chris Kawa Moderators last edited by

                    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 {
                    ...
                    signals:
                    void myCustomSignal();
                    public:
                    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);
                    }
                    @

                    1 Reply Last reply Reply Quote 0
                    • Y
                      yakine last edited by

                      thank you and sorry Chris kawa

                      the problem it solved thank you again

                      IF YOU HAVE MERCY ON PEOPLE GOD HAVE MERCY ON YOU

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post