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. Opening a Widget created in Designer, from a Main Window
QtWS25 Last Chance

Opening a Widget created in Designer, from a Main Window

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 809 Views
  • 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.
  • S Offline
    S Offline
    snoop911
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      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