Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Using 2 or more .ui files together
Forum Updated to NodeBB v4.3 + New Features

Using 2 or more .ui files together

Scheduled Pinned Locked Moved Qt Creator and other tools
10 Posts 3 Posters 6.8k 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
    manasij7479
    wrote on last edited by
    #1

    I'm relatively new to QT and am using the designer to reduce the slope of the learning curve.
    My question, now is about using two windows..(as an example.. Help->About)
    I already have the main window and the menus, then I made a dialog form by Forms-> Add New.
    How do I set it up so that the About action will be linked to the showing of the other dialog window?

    "Error, no keyboard — press F1 to continue."

    1 Reply Last reply
    0
    • H Offline
      H Offline
      HuXiKa
      wrote on last edited by
      #2

      Something like this:

      @....
      connect(ui->actionAbout,SIGNAL(clicked()),this,SLOT(showAbout());
      ...
      void MainWindow::showAbout()
      {
      AboutDialog *about = new AboutDialog(this);
      about->exec();

      // or you can use this also
      // QMessageBox::about(this, tr("Title"),tr("About"));
      }@

      edit: fixed, sorry for the wrong tip

      If you can find faults of spelling in the text above, you can keep them.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Franzk
        wrote on last edited by
        #3

        General course of action:

        Create a slot function in your main window.

        @class MyClass : public QMainWindow {
        ...
        public slots:
        void showAbout();
        ...
        @

        In that function, create the widget or dialog
        @void MyClass::showAbout()
        {
        AboutDialog *dlg = new AboutDialog(this);
        dlg->setAttribute(Qt::WA_DeleteOnClose, true);
        dlg->open(); // window modal
        }
        @

        in the appropriate place, possibly constructor or using designer, connect the menu action clicked() signal to your slot.
        @connect(ui->actionAbout, SIGNAL(clicked()), this, SLOT(showAbout()));@

        I don't really know how to do that last step with designer anymore :P.

        "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on last edited by
          #4

          [quote author="HuXiKa" date="1308144526"]Something like this:

          @void MainWindow::showAbout()
          {
          aboutDialog about;
          about.show();
          }@
          [/quote]
          This particular piece of code will not work as expected, because the dialog is destroyed when you go out of scope. about.exec() would be the function of choice in this case (the other solution is "somewhat safer":http://labs.qt.nokia.com/2010/02/23/unpredictable-exec/ though).

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • H Offline
            H Offline
            HuXiKa
            wrote on last edited by
            #5

            [quote author="Franzk" date="1308144781"]
            I don't really know how to do that last step with designer anymore :P.[/quote]

            It's a little bit complicated, but my method is:
            1: F4-> slot mode, try to create a connection between something and the MainWindow,
            2: in the pop-up window add your slot to the MainWindow,
            3: create your normal signal-slot connection (in the bottom right corner).

            But I'm sure there is an easier way to do this :)

            If you can find faults of spelling in the text above, you can keep them.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Franzk
              wrote on last edited by
              #6

              [quote author="HuXiKa" date="1308145202"]But I'm sure there is an easier way to do this :)[/quote]Coding it :P

              "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • H Offline
                H Offline
                HuXiKa
                wrote on last edited by
                #7

                For some reason I don't really like to see a bunch of connect()-s outside the ui files (just the necessary ones, which can't be made with the Editor). But this is just my matter of taste.

                If you can find faults of spelling in the text above, you can keep them.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  manasij7479
                  wrote on last edited by
                  #8

                  I followed the following steps..point out where it goes wrong:

                  1. Created a new .ui file...(The name of the Object being AboutDialog)
                    2.Followed Franzk's first post.
                    <AboutDialog is not recognized and
                    the slot is not accessible from designer>

                  "Error, no keyboard — press F1 to continue."

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    Franzk
                    wrote on last edited by
                    #9

                    Did you include the necessary headers (aboutdialog.h) in your main window cpp file?

                    "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      manasij7479
                      wrote on last edited by
                      #10

                      There is only the .ui file for that...I created the dialog with the designer..
                      How do I include ui files?

                      "Error, no keyboard — press F1 to continue."

                      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