Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Opening a Widget created in Designer, from a Main Window
snoop911 last edited by
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
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:
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
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.
- Open new project and use QMainWindow with form.
- Compile and launch it.
- 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
- Add TestWidget.h to your main.cpp
- 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.