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. Have Form, now what?
Forum Updated to NodeBB v4.3 + New Features

Have Form, now what?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 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.
  • M Offline
    M Offline
    Michael.R.LegakoL-3com.com
    wrote on last edited by
    #1

    I doing my very 1st QT project. I started the project as a QT Widgets application. After adding a few widgets to the form, I decided to add another form to use as a non-modal dialog. Now I want to use a button from the starting form to open the 2nd (non-modal dialog). (C code for the original form was created when the project began, and I've got a 'clicked' slot function setup for my button). My question is: How is the class for the 2nd form created, and/or how do I get the 2nd form and the code for it to be associated? (I know this is QT-101, but its surprisingly not obvious...

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Michael.R.LegakoL-3com.com
      wrote on last edited by
      #2

      For anybody trying to add a 2nd dialog, the solution that worked for me was to do the following from inside QT Creator:

      1. Open or create the project
      2. Right click on the project (top line in 'Projects' view)
      3. Select 'Add New...'
      4. In the 'New File' dialog, Choose Qt -> QT Designer Form Class. This will generate ( *.ui, *.h, and *.cpp) for the new form.
      5. From there you open your mainwindow ui, and select the button you want to open the modal dialog and right click on 'Goto slot'.
      6. Select the 'clicked' slot, and this will add a 'clicked' function to your mainwindow code. Then startup the new modal dialog by editing the button 'clicked' function as follows:

      @
      void MainWindow::on_Button_clicked()
      {
      NewDlg *Dlg = new NewDlg;
      Dlg->show();
      }
      @

      [edit: Added missing coding tags @ SGaist]

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

        Hi and welcome to devnet,

        It's the right technique. However you have now a memory leak with your dialog

        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
        • M Offline
          M Offline
          Michael.R.LegakoL-3com.com
          wrote on last edited by
          #4

          Thanks for the tip. I'll change the code to make NewDlg a member variable of MainWindow, and then have the WinWindow destructor delete the pointer. (I guess another way would be to have the dialog delete its own space in its destructor?

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

            It depends on how you use your dialog. Is it meant to stay ? Or does the user just answer a question and close it ?

            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