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. Method "setupUi" is not found in a window constructor.
Forum Updated to NodeBB v4.3 + New Features

Method "setupUi" is not found in a window constructor.

Scheduled Pinned Locked Moved General and Desktop
18 Posts 5 Posters 17.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.
  • L Offline
    L Offline
    lyuts
    wrote on last edited by
    #8

    My first question is: Why do you do this:
    @#ifdef USE_MAIN_WINDOW_POINTER
    : QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }
    #else
    : QMainWindow(parent)
    {
    setupUi(this);
    }
    #endif@

    What benefits do you get? I think you pick one way and follow it. Otherwise you get headache.

    I'm a rebel in the S.D.G.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      elfring
      wrote on last edited by
      #9

      [quote author="Volker" date="1287616637"]QWidget does not provide any setupUI() method.[/quote]

      I get other informations from the "documentation":http://doc.qt.nokia.com/4.7/qwidget.html#setupUi.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        goetz
        wrote on last edited by
        #10

        The note in the docs says it clearly:

        bq. from the docs:
        Sets up the user interface for the specified widget.
        Note: This function is available with widgets that derive from user interface descriptions created using uic.

        If you do not derive from the Ui::MainWindow class you do NOT have this function.

        But anyways - did you try it already? It really works in real programs, trust me ;-)

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

        1 Reply Last reply
        0
        • E Offline
          E Offline
          elfring
          wrote on last edited by
          #11

          [quote]What benefits do you get?[/quote]

          I try to use an easier design approach for my use case.

          [quote]I think you pick one way and follow it.[/quote]

          I would like to call the member function "setupUi" directly (without an intermediate pointer).
          Unfortunately, I was surprised by the error message "‘setupUi’ was not declared in this scope".

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #12

            bq. I would like to call the member function “setupUi” directly (without an intermediate pointer).
            Unfortunately, I was surprised by the error message ”‘setupUi’ was not declared in this scope”.

            That's easy. Inherit privately from Ui::MainWindow and you're done.

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

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lyuts
              wrote on last edited by
              #13

              There are three ways of embedding your ui into your class:

              1. Private inheritance.
              2. Aggregation.
              3. Aggregation by pointer.

              The one of the above should be picked and used.

              Looking at your USE_MAIN_WINDOW_POINTER I start to think you are trying to mix those.

              As for ui header, then

              @#include "ui_mainwindow.h"@

              this should be in MainWindow.h.

              And I think you should remove this part:
              @namespace Ui {
              class MainWindow;
              }@

              I'm a rebel in the S.D.G.

              1 Reply Last reply
              0
              • E Offline
                E Offline
                elfring
                wrote on last edited by
                #14

                I would prefer inheritance for my use case here.

                [quote]Looking at your USE_MAIN_WINDOW_POINTER I start to think you are trying to mix those.[/quote]

                That's not my intention. I kept the flag to show that the "Pimpl design approach":http://en.wikipedia.org/wiki/Private_class_data_pattern#Also_known_as works as usual.

                I do also not get rid of the unexpected error message if I reduce the affected declaration to the following.
                mainwindow.h:
                @#ifndef MAIN_WINDOW_H
                #define MAIN_WINDOW_H
                #include <QMainWindow>

                class MainWindow : public QMainWindow
                {
                Q_OBJECT
                public:
                explicit MainWindow(QWidget* parent = 0);
                };
                #endif
                @

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #15

                  Of course you get the error message. You still do not inherit from your Ui::MainWindow GUI class.

                  Just follow the example in the "docs":http://doc.trolltech.com/main-snapshot/designer-using-a-ui-file.html#the-multiple-inheritance-approach

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

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    elfring
                    wrote on last edited by
                    #16

                    [quote author="Volker" date="1287690429"]You still do not inherit from your Ui::MainWindow GUI class.[/quote]

                    I have got the impression that the suggested inheritance is already applied if the pointer attribute is used in my example. The name space "Ui" contains just a "forward declaration":http://codepedia.com/1/CppForwardDeclaration as a recommendation from the Qt application template. (I can even try to omit this design detail.)

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on last edited by
                      #17

                      Of course you can omit the forward declaration. In case you inherit you must include the header file (ui_mainwindow.h in your case).

                      You did read the section "The Multiple Inheritance Approach" in the link mentioned above, didn't you? The example there is exactly what you want. Just start from scratch (leaving out your #defines and #ifdefs), replace QWidget with QMainWindow and CalculatorForm with MainWindow and you're done.

                      BTW: How do you manage to inherit from something, that you don't put into the inheritance list of your class declaration?

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

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        elfring
                        wrote on last edited by
                        #18

                        You are right. I have needed a bit more time to understand the involved dependencies in this Qt application context.

                        I admit that all adjustment consequences were not completely clear for me so far while switching from a "Direct Approach" to a design approach with single or multiple inheritance.

                        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