Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. pass variable from tab to dialog
Forum Updated to NodeBB v4.3 + New Features

pass variable from tab to dialog

Scheduled Pinned Locked Moved Solved General and Desktop
29 Posts 3 Posters 5.2k Views 2 Watching
  • 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.
  • TheCipo76T Offline
    TheCipo76T Offline
    TheCipo76
    wrote on last edited by TheCipo76
    #1

    Hi,
    i've populated (from database) a tabwidget in a dialog with this code :

    ui->tabWidget->clear();
            if (ui->comboBox_Codice->currentText() == " ") {
                return;
            }
            ui->tabWidget->addTab(new tabcomplessivo(this, c.value(0).toString()), ui->comboBox_Codice->currentText());
            do {
            ui->tabWidget->addTab(new tabcomponente(this, comp.value(0).toString()), comp.value(0).toString());
            } while (comp.next());
    

    and it work fine..
    now i want to populate a tableview (in the dialog) with variable.

    this is dialog:
    0_1541112472410_Schermata 2018-11-01 alle 23.40.03.png

    on "Aggiorna" click i have to pass data to dialog
    to polulate tableview..

    how can i pass the data (LAVORAZIONE, MACCHINA, PZORA) from tab combobox to dialog??

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Where's the data coming from ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • TheCipo76T Offline
        TheCipo76T Offline
        TheCipo76
        wrote on last edited by TheCipo76
        #3

        from database
        i had put it in different combobox as you see in the picture:
        LAVORAZIONE, MACCHINA, PZORA

        now i want populate tableview (with abstracttablemodel i think)
        on "Aggiorna" click

        0_1541113763503_Schermata 2018-11-02 alle 00.02.44.png

        from tabcomplessivo (0059.0430)-> to dialog
        from tabcomponente (0040.0153/0065.0040/0065.0041/0065.0042/0065.0043)-> to dialog

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          If you make a model with data from the database, and then use
          http://doc.qt.io/qt-5/qdatawidgetmapper.html
          to hook up the combo boxes, you can then hook up tableview to same model
          and it should automatically update when user select new data in tabcomplessivo etc.

          I asume you did see
          http://doc.qt.io/qt-5/qsqltablemodel.html
          but it didnt fit your use case. (being single table ) ?

          TheCipo76T 1 Reply Last reply
          2
          • mrjjM mrjj

            Hi
            If you make a model with data from the database, and then use
            http://doc.qt.io/qt-5/qdatawidgetmapper.html
            to hook up the combo boxes, you can then hook up tableview to same model
            and it should automatically update when user select new data in tabcomplessivo etc.

            I asume you did see
            http://doc.qt.io/qt-5/qsqltablemodel.html
            but it didnt fit your use case. (being single table ) ?

            TheCipo76T Offline
            TheCipo76T Offline
            TheCipo76
            wrote on last edited by
            #5

            @mrjj
            the comboboxes was populated from different databases

            tableview in only a preview of data

            on "Registra" click i will store the data from tableview to another database

            qdatawidgetmapper is very interesting but i'm not sure this is my way.

            Any suggestions?

            mrjjM 1 Reply Last reply
            0
            • TheCipo76T TheCipo76

              @mrjj
              the comboboxes was populated from different databases

              tableview in only a preview of data

              on "Registra" click i will store the data from tableview to another database

              qdatawidgetmapper is very interesting but i'm not sure this is my way.

              Any suggestions?

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @TheCipo76
              Hi
              Does the data from tableview live in one table or across multiple tables ? ( mean when saved to db)

              TheCipo76T 1 Reply Last reply
              0
              • mrjjM mrjj

                @TheCipo76
                Hi
                Does the data from tableview live in one table or across multiple tables ? ( mean when saved to db)

                TheCipo76T Offline
                TheCipo76T Offline
                TheCipo76
                wrote on last edited by
                #7

                @mrjj i have to save the tableview data in only one database

                mrjjM 1 Reply Last reply
                0
                • TheCipo76T TheCipo76

                  @mrjj i have to save the tableview data in only one database

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @TheCipo76
                  and in this context, one database is one table ?
                  Im asking as you could use QSqlTableModel
                  and write the data from the comboboxes to
                  the model and view ould just show it. ( and be saved)
                  https://stackoverflow.com/questions/47318601/inserting-row-into-qsqltablemodel

                  TheCipo76T 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @TheCipo76
                    and in this context, one database is one table ?
                    Im asking as you could use QSqlTableModel
                    and write the data from the comboboxes to
                    the model and view ould just show it. ( and be saved)
                    https://stackoverflow.com/questions/47318601/inserting-row-into-qsqltablemodel

                    TheCipo76T Offline
                    TheCipo76T Offline
                    TheCipo76
                    wrote on last edited by
                    #9

                    @mrjj sorry.. yes is only one table in the same database

                    i'm already using QSqlTableModel in my app

                    but if i use QSqlTableModel for the tableview the data was stored immediately on the database..

                    instead i want only populate it with comboboxes (to generate a preview)
                    and then store the data only with "Registra" click (after that i have checked input by code)..

                    all to prevent duplication, error and other problem that can be created by users input.

                    mrjjM 1 Reply Last reply
                    0
                    • TheCipo76T TheCipo76

                      @mrjj sorry.. yes is only one table in the same database

                      i'm already using QSqlTableModel in my app

                      but if i use QSqlTableModel for the tableview the data was stored immediately on the database..

                      instead i want only populate it with comboboxes (to generate a preview)
                      and then store the data only with "Registra" click (after that i have checked input by code)..

                      all to prevent duplication, error and other problem that can be created by users input.

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @TheCipo76
                      Ah, i assumed user could only select valid data from the combo boxes.
                      But you could change
                      QSqlTableModel::setEditStrategy() to QSqlTableModel::OnManualSubmit
                      check the model from code and do
                      QSqlTableModel::submitAll() to save to db.
                      ?

                      TheCipo76T 1 Reply Last reply
                      1
                      • mrjjM mrjj

                        @TheCipo76
                        Ah, i assumed user could only select valid data from the combo boxes.
                        But you could change
                        QSqlTableModel::setEditStrategy() to QSqlTableModel::OnManualSubmit
                        check the model from code and do
                        QSqlTableModel::submitAll() to save to db.
                        ?

                        TheCipo76T Offline
                        TheCipo76T Offline
                        TheCipo76
                        wrote on last edited by TheCipo76
                        #11

                        @mrjj how can i access to tabs comboboxes data from mainwindow??

                        i've declarated in .h file like "public" all the comboboxes (in all the tab forms)

                        when i click "Aggiorna" i want to read all comboboxes of all tabs (with 2 nidificated loop: 1 for all tab, and inside the first, 1 for all comboboxes of each tab) and populate the qsqltablemodel (tableview) in mainwindow form

                        i'm trying to store all data in some QString before to insert in model

                        i've tried with this code:

                        Lavorazione = tabcomplessivo::array_Lavorazione[j]->currentText();
                        

                        but i have this error:

                        invalid use of non-static data member 'array_Lavorazione'

                        mrjjM 1 Reply Last reply
                        0
                        • TheCipo76T TheCipo76

                          @mrjj how can i access to tabs comboboxes data from mainwindow??

                          i've declarated in .h file like "public" all the comboboxes (in all the tab forms)

                          when i click "Aggiorna" i want to read all comboboxes of all tabs (with 2 nidificated loop: 1 for all tab, and inside the first, 1 for all comboboxes of each tab) and populate the qsqltablemodel (tableview) in mainwindow form

                          i'm trying to store all data in some QString before to insert in model

                          i've tried with this code:

                          Lavorazione = tabcomplessivo::array_Lavorazione[j]->currentText();
                          

                          but i have this error:

                          invalid use of non-static data member 'array_Lavorazione'

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #12

                          @TheCipo76

                          Hi
                          The syntax you are using would mean a static variable. ( hence the error)
                          You need a pointer to the dialog. ( i assume the combobox are in other dialog ? )
                          dialogptr->tabcomplessivo->array_Lavorazione[j]->currentText();

                          Often you would do it same place where you show dialog
                          like
                          TheDialog dia; // we dont need to NEW it as we use exec() which blocks.
                          if(dia.exec() == QDialog::Accepted)
                          {
                          // grab the data
                          dia.tabcomplessivoPtr.array_Lavorazione[j]->currentText();
                          ...
                          }

                          TheCipo76T 1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            Are you only preparing the data to be stored in the database or will you also be showing entries from the database in that table view ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            TheCipo76T 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @TheCipo76

                              Hi
                              The syntax you are using would mean a static variable. ( hence the error)
                              You need a pointer to the dialog. ( i assume the combobox are in other dialog ? )
                              dialogptr->tabcomplessivo->array_Lavorazione[j]->currentText();

                              Often you would do it same place where you show dialog
                              like
                              TheDialog dia; // we dont need to NEW it as we use exec() which blocks.
                              if(dia.exec() == QDialog::Accepted)
                              {
                              // grab the data
                              dia.tabcomplessivoPtr.array_Lavorazione[j]->currentText();
                              ...
                              }

                              TheCipo76T Offline
                              TheCipo76T Offline
                              TheCipo76
                              wrote on last edited by
                              #14

                              @mrjj
                              as you can see in the first post isn't a dialog but
                              tabcomplessivo and tabcomponente were
                              simple forms pass like tabs to tabwidget

                              mrjjM 1 Reply Last reply
                              0
                              • TheCipo76T TheCipo76

                                @mrjj
                                as you can see in the first post isn't a dialog but
                                tabcomplessivo and tabcomponente were
                                simple forms pass like tabs to tabwidget

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                @TheCipo76
                                So they are actual inside the mainwindow ?

                                TheCipo76T 1 Reply Last reply
                                0
                                • mrjjM mrjj

                                  @TheCipo76
                                  So they are actual inside the mainwindow ?

                                  TheCipo76T Offline
                                  TheCipo76T Offline
                                  TheCipo76
                                  wrote on last edited by
                                  #16

                                  @mrjj Yes

                                  1 Reply Last reply
                                  0
                                  • SGaistS SGaist

                                    Are you only preparing the data to be stored in the database or will you also be showing entries from the database in that table view ?

                                    TheCipo76T Offline
                                    TheCipo76T Offline
                                    TheCipo76
                                    wrote on last edited by TheCipo76
                                    #17

                                    @SGaist only prepare a preview
                                    then (on "Registra" click) it will be stored in db

                                    otherwise the tableview need filter in order to don't show (and modify) other data (item) in the table

                                    both case is good however

                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      In that case, wouldn't it be easier to use a QTableWidget to setup the rows and then QSqlQuery to update your database when you click on Registra

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      TheCipo76T 1 Reply Last reply
                                      0
                                      • SGaistS SGaist

                                        In that case, wouldn't it be easier to use a QTableWidget to setup the rows and then QSqlQuery to update your database when you click on Registra

                                        TheCipo76T Offline
                                        TheCipo76T Offline
                                        TheCipo76
                                        wrote on last edited by TheCipo76
                                        #19

                                        @SGaist yes but i can't access to data in tabcomplessivo and tabcomponente
                                        as i've already wrote up they were in the mainwindow and declared pulic

                                        1 Reply Last reply
                                        0
                                        • SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #20

                                          Just to be sure, do you have several different widgets that you built with designer and that you are putting together in that dialog ?

                                          Interested in AI ? www.idiap.ch
                                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          TheCipo76T 1 Reply Last reply
                                          1

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved