Opening a Widget created in Designer, from a Main Window



  • I've created 2 .ui files, one is a main window, the other a widget. Designer builds the 2 header files each with QT_BEGIN_NAMESPACE around the class declaration.

    The problem is, what works in opening my main window, does not work in opening the second widget window!

    To display my main window, I created a class that inherits from my .ui file:
    class myWindow: public QMainWindow, private Ui::uiClassWindow
    setupUi(this);

    That opens fine, so then to open the second widget window, I declare a generic widget object and then save it with a pointer to my Widget Ui Header file:
    QWidget newWidget;
    setupUi(newWidget)

    But setupUi resolves to my Main Window header file... How do I tell it to use the Widget's SetupUi?

    I'm not sure how to use namespaces, so is that part of the problem? I'm kinda stumbling around enough to get things to work, but would love some feedback if there's a better or more typical way of doing all of this

    Thanks



  • Definitely it is not a name space issue. You must passing wrong class to your pointers somewhere. Please do the following and see how it goes. Unless we have code, difficult at see what is happening.

    1. Open new project and use QMainWindow with form.
    2. Compile and launch it.
    3. For the same project add "New File->Qt->QtDesignerFormClass".
      Use Widget this time. This will generate entire template based on the widget. Call this as TestWidget
    4. Add TestWidget.h to your main.cpp
    5. Create the instance of TestWidget in main.cpp and show it.

    This should launch two windows for you. Now you can look at how things and fix your issue.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.