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. Insert data in QSqlTableModel based on checkbox choices
Forum Updated to NodeBB v4.3 + New Features

Insert data in QSqlTableModel based on checkbox choices

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 3.7k Views 1 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.
  • F Offline
    F Offline
    fepelipe
    wrote on last edited by
    #1

    I have this dialog opened by the main window:
    @void MainWindow::on_pushButton_clicked()
    { //Add

    DiagAddProf dAddProf;
    if (dAddProf.exec() == QDialog::Accepted){
        dAddProf.setRoleProf(dataRole);
    }
    

    }@

    "dataRole" is a QSqlTableModel that i'm trying to pass to the dAddProf dialog, so it can use the setRoleProf method.
    The setRoleProf method verifies if every single checkbox, 9 of them, "isChecked()", then it adds the EditText typed text and the roles selected on the checkboxes in a row of dAddProf. It adds a row in the database for each relation (name, role).
    However, it seems i'm not able to do that. Main problem is, I tried to use signals and slots too, but it seems I can't just declare QSqlTableModel as a parameter for the setRoleProf function in the .h file, even importing QSql. Is there any other way to do this?

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

      Hi and welcome to devnet,

      What's the exact error you get ? What is setRoleProf signature ?

      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
      0
      • F Offline
        F Offline
        fepelipe
        wrote on last edited by
        #3

        I'm so sorry for not answering this earlier, I'm getting back to this project right now.

        The error for diagaddprof is:
        diagaddprof.cpp:23: error: prototype for 'void DiagAddProf::setRoleProf(QSqlTableModel)' does not match any in class 'DiagAddProf'

        setRoleProf is declared as:
        @void DiagAddProf::setRoleProf(QSqlTableModel tableRole)@

        And for the diagaddprof.h I have the header for the setRoleProf method:
        @public:
        QString getNameProf();
        void setRoleProf(QSqlTableModel *tableRole);
        explicit DiagAddProf(QWidget *parent = 0);
        ~DiagAddProf();@

        Note that #include <QSql> is in this header.

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

          You have a signature mismatch.

          In your header you have a pointer to a QSqlTable model but not in your implementation

          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
          0
          • F Offline
            F Offline
            fepelipe
            wrote on last edited by
            #5

            I corrected that, but there's another error now.
            mainwindow.cpp:98: error: no matching function for call to 'DiagAddProf::setRoleProf(QSqlTableModel&)'

            diagaddprof.h:17: candidates are: void DiagAddProf::setRoleProf(QSqlTableModel)*

            mainwindow.cpp:98 refers to:
            @dAddProf.setRoleProf(dataRole);@

            as seen on the first post, being dataRole declared as:
            @dataProf = new QSqlTableModel(this);@

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

              How did you corrected that ? Adding a * in you implementation or removing the * from your header ?

              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
              0
              • F Offline
                F Offline
                fepelipe
                wrote on last edited by
                #7

                I corrected that, but there's another error now.
                mainwindow.cpp:98: error: no matching function for call to 'DiagAddProf::setRoleProf(QSqlTableModel*&)'

                diagaddprof.h:17: candidates are: void DiagAddProf::setRoleProf(QSqlTableModel)

                mainwindow.cpp:98 refers to:
                @dAddProf.setRoleProf(dataRole);@

                as seen on the first post, being dataRole declared as:
                @dataRole = new QSqlTableModel(this);@

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

                  @void setRoleProf(QSqlTableModel *tableRole)
                  void DiagAddProf::setRoleProf(QSqlTableModel *tableRole)
                  @

                  Is the correct thing to have

                  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
                  0
                  • F Offline
                    F Offline
                    fepelipe
                    wrote on last edited by
                    #9

                    Oh, thanks! Right, and added to that, that #include <QSql> is quite wrong, its QtSql... I just corrected that. It seemed strange that QSqlTableModel wasn't highlighted in the header...

                    So now I got a pointer to the table. How can i effectively use the actual table?

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

                      I would say that using the global includes are bad (they are useful when doing a quick test application or jumpstarting the development). They pull in all other headers that will get parsed and it'll slow down compilation. Just include what you use at the right place.

                      Well... Just call the functions you want/need on it. I don't know what you want to do with it so I can't really answer that question.

                      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
                      0
                      • F Offline
                        F Offline
                        fepelipe
                        wrote on last edited by
                        #11

                        Thanks a lot for all the tips and help (:

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

                          You're welcome !

                          If all your questions are answered don't forget to update the thread's title to solved so other forum users may know a solution has been found :)

                          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
                          0

                          • Login

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