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. SQL Queries and passing to Child Dialogs, best practices?
QtWS25 Last Chance

SQL Queries and passing to Child Dialogs, best practices?

Scheduled Pinned Locked Moved Unsolved General and Desktop
sqlmysqlsqlquerymodel
11 Posts 3 Posters 2.5k Views
  • 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.
  • D Offline
    D Offline
    DaveK 0
    wrote on last edited by aha_1980
    #1

    #MySQL #SQL
    Hi!
    I have a main window that connects to a DB (MySQL in AWS) to show table data. I have child dialog windows that also query the DB to show/update table data, so I have created signals so that the child windows can pass any necessary variables or queries to the main window which runs the actual query.

    (I did this to try and cut down on having multiple connections to the DB unnecessarily instead of having each window or dialog connect individually, and then disconnect upon close).

    I now need grand-child dialogs that can do the same. Having signals/slots from the main window->child dialog->grand-child dialog seems overly cumbersome.

    Is there a better way? Should I not worry about having too many connections and just have each window/dialog connect to the DB individually?

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

      Hi,

      It depends on how you want your software to manage the database connection(s).

      Only one can be enough.

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

      D 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        It depends on how you want your software to manage the database connection(s).

        Only one can be enough.

        D Offline
        D Offline
        DaveK 0
        wrote on last edited by
        #3

        @SGaist How would you recommend passing data between grant-parent/grand-child Windows with only one connection?

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

          What kind of data do you want to pass ?

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

          D 1 Reply Last reply
          0
          • D DaveK 0

            #MySQL #SQL
            Hi!
            I have a main window that connects to a DB (MySQL in AWS) to show table data. I have child dialog windows that also query the DB to show/update table data, so I have created signals so that the child windows can pass any necessary variables or queries to the main window which runs the actual query.

            (I did this to try and cut down on having multiple connections to the DB unnecessarily instead of having each window or dialog connect individually, and then disconnect upon close).

            I now need grand-child dialogs that can do the same. Having signals/slots from the main window->child dialog->grand-child dialog seems overly cumbersome.

            Is there a better way? Should I not worry about having too many connections and just have each window/dialog connect to the DB individually?

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @DaveK-0 said in SQL Queries and passing to Child Dialogs, best practices?:

            grand-child dialogs

            Usually with dialogs the process is:

            1. parent create the child dialog
            2. parent calls QDialog::exec()
            3. if the user clicked ok the parent reads the data directly exposed via getters
            4. the parent does stuff with that data

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            D 1 Reply Last reply
            2
            • SGaistS SGaist

              What kind of data do you want to pass ?

              D Offline
              D Offline
              DaveK 0
              wrote on last edited by
              #6

              @SGaist I would like to pass a QSqlQueryModel.

              1 Reply Last reply
              0
              • VRoninV VRonin

                @DaveK-0 said in SQL Queries and passing to Child Dialogs, best practices?:

                grand-child dialogs

                Usually with dialogs the process is:

                1. parent create the child dialog
                2. parent calls QDialog::exec()
                3. if the user clicked ok the parent reads the data directly exposed via getters
                4. the parent does stuff with that data
                D Offline
                D Offline
                DaveK 0
                wrote on last edited by DaveK 0
                #7

                @VRonin I am wondering if there is a way for my dialog, which is a child of a child of a main window to access a getter function of the main window, without having to have an intermediary getter function in the ‘middle’ dialog.

                How should I point to a dialog’s parent’s parent?

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

                  If you have to go in such deep levels, then there's likely an architecture problem.

                  What exactly are you trying to achieve ?

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

                  D 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    If you have to go in such deep levels, then there's likely an architecture problem.

                    What exactly are you trying to achieve ?

                    D Offline
                    D Offline
                    DaveK 0
                    wrote on last edited by
                    #9

                    @SGaist I am creating a desktop application to handle inventory movement between multiple warehouses and for multiple projects.

                    The MainWindow shows general information about what inventory is on hand at each location for each project.

                    A child Dialog, lets call it "CreateTransaction" is used for creating a new 'transaction' or shipment of inventory between warehouses. This dialog shows information about the individual shipment (tracking info, shipment dates, and what various part#'s and QTY's are in the shipment).

                    While a user is creating a transaction, I would like them to be able to get a list of all the available inventory part#'s and QTY's in the warehouse that they are shipping from. So to add each individual line item to a shipment a child of "CreateTransaction" is created. Lets call it "AddTransactionLine". A user may add one, or several lines of different inventory to a transaction.

                    AddTransactionLine is a child of CreateTransaction, which is a child of MainWindow (which handles the DB connection).
                    AddTransactionLine should be able to query the database to get a table. The user selects qty's from the table, and then will pass that info along to "CreateTransaction" to actually add them as a "line" in the shipment.

                    I would like to avoid having to build the part where you add individual line items to a "transaction" into the UI of CreateTransaction as it would look cluttered, and most other inventory programs I have used in the past use this same kind of 3-tiered logic of Home Screen > Create A Shipment > Add things to that shipment.

                    Any suggestions?

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DaveK 0
                      wrote on last edited by
                      #10

                      I think I have my solution: Pass a pointer to a class instantiated by the MainWindow to each subsequent dialog(s) and save it as a member. The object instance I am passing, call it "DatabseObject" has getter functions that run queries, return models, etc. This way any dilalog can call a getter function on my DatabaseObject, without creating a long series of siganls/slots.

                      https://stackoverflow.com/questions/44355446/qt-passing-objects-to-every-window
                      Pseudo Code:

                      1.  MainWindow instantiates object of class "Database" as *m_pDBO (DBO = database object).
                      2.  MainWindow passes m_pDBO to any dialogs created, they also save it as a *m_pDBO.
                      3.  Any further dialogs created by dialogs, get passed m_pDBO.
                      

                      Any comments, better methods, or reasons why I should not do this are always appreciated!

                      1 Reply Last reply
                      0
                      • VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on last edited by
                        #11

                        No, bad design. The child should never even know who its parent is.

                        The correct process is to push information downstream.

                        The child should have setters for all the data it need. The manwindow calls those setters.

                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                        ~Napoleon Bonaparte

                        On a crusade to banish setIndexWidget() from the holy land of Qt

                        1 Reply Last reply
                        3

                        • Login

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