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. QDialog to QDialog communication
Qt 6.11 is out! See what's new in the release blog

QDialog to QDialog communication

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.4k 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.
  • W Offline
    W Offline
    WhatIf
    wrote on last edited by
    #1

    Hi,

    I want info to be passed from one QDialog to another. Should this be handled by signal/slot or is there another mechanism to handle the task?

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

      Hi
      While you can use plain functions, signals & slots are far Superior as you hide the details
      from rest of the program.

      So you simple define a set of signals and slot that defines what they want to "say" to each other
      and then hook it up.

      1 Reply Last reply
      1
      • W Offline
        W Offline
        WhatIf
        wrote on last edited by
        #3

        Just need a clarification

                close();
                Information* info = retrieveInfo();
                InformationDialog infoDialog;
                infoDialog.setModal(true);
                connect(this, SIGNAL(InfoChanged(Information*)), &infoDialog, SLOT(on_Info_Changed(Information*)));
                emit on_Info_Changed(Information);
                infoDialog.exec();
        

        basically I want the first dialog to search for information and then close and display the information on the 2nd dialog. The above code works but I just don't get how "this" in connect() still exists after the call to close();

        Will this code cause problems?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jan-Willem
          wrote on last edited by Jan-Willem
          #4

          @WhatIf said:

          close

          Perhaps because the first dialog is closed but not deleted from memory?
          You could set the Qt::WA_DeleteOnClose flag and see if it still works.

          1 Reply Last reply
          0
          • W Offline
            W Offline
            WhatIf
            wrote on last edited by
            #5

            When I set the Qt::WA_DeleteOnClose flag, the program crashes when I click cancel in the 2nd dialog, which calls close().

            Also, it the order of

            emit on_Info_Changed(Information);
            infoDialog.exec();
            

            correct?

            mrjjM 1 Reply Last reply
            0
            • W WhatIf

              When I set the Qt::WA_DeleteOnClose flag, the program crashes when I click cancel in the 2nd dialog, which calls close().

              Also, it the order of

              emit on_Info_Changed(Information);
              infoDialog.exec();
              

              correct?

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

              @WhatIf
              Hi
              close dont call delete (unless flag set) so that is why it works.
              the "this" is still valid and we block at infoDialog.exec() so
              its not deleted behind our back.

              When i read your question i assumed you would have dialogs open at the same time. hence signal would be the best. But it more like in sequence i see

              it could be a bit cleaner if you can let mainwindow handle it and we then get rid of "one dialog open the other one" as its best to avoid if possible.
              Its not wrong as such but not optimal as Qt::WA_DeleteOnClose can crash the
              code.

              what about something like ?

              void mainwindow::Search() {
                SeachDia SD;
                InformationDialog infoDialog () ;
                if ( SD.exec() == Accepted) {
                  Information* info = SD.retrieveInfo();
                  infoDialog.setSearchData(info);
                  infoDialog.exec();
                }
              }
              
              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