Results 1 to 4 of 4

Thread: New window doesn't open even though I initialize QMainWindow parent class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2021
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default New window doesn't open even though I initialize QMainWindow parent class

    Hello there!

    I'm currently working on a project for my resumé that is supposed to be a GUI based login system. It's been going pretty well until now. I want to open a new window for the LoggedIn class after you have successfully logged in but it doesn't open a new window and I don't for the life of me get why. Please excuse my awful code, I haven't taken the time to tidy things up but here it is:

    https://github.com/FlatEarthGary/log...b/main/main.py

    Any help as well suggestions on improvements is highly appreciated, thank you and have a great day!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,972
    Thanks
    277
    Thanked 808 Times in 797 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: New window doesn't open even though I initialize QMainWindow parent class

    There is too much code there to spend the time to understand it all. However, both of your top-level window classes seem to be derived from QMainWindow (which is strange), and you have another window class that is derived from main, which is derived from QMainWindow (doubly strange).

    I think you are confusing QMainWindow for a generic top-level QWidget, which can be any widget without a parent.

    A more typical scenario would be to have the initial window be a QDialog which is used to log in the user after validation. The slot that handles the login validation should create the single QMainWindow instance that represents your app's GUI, and then show() it before closing itself.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2021
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: New window doesn't open even though I initialize QMainWindow parent class

    Quote Originally Posted by d_stranz View Post
    There is too much code there to spend the time to understand it all. However, both of your top-level window classes seem to be derived from QMainWindow (which is strange), and you have another window class that is derived from main, which is derived from QMainWindow (doubly strange).

    I think you are confusing QMainWindow for a generic top-level QWidget, which can be any widget without a parent.

    A more typical scenario would be to have the initial window be a QDialog which is used to log in the user after validation. The slot that handles the login validation should create the single QMainWindow instance that represents your app's GUI, and then show() it before closing itself.
    Hey, thank you for your reply! I really appreciate you taking time out of your day to help me out!

    You have given me quite a bit to take look at, that's great, thank you! If I have understood this correct you're only supposed to have one instance of the QMainWindow and all other should rely on QWidget or QDialog?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,972
    Thanks
    277
    Thanked 808 Times in 797 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: New window doesn't open even though I initialize QMainWindow parent class

    If I have understood this correct you're only supposed to have one instance of the QMainWindow and all other should rely on QWidget or QDialog?
    A typical desktop app will have only one QMainWindow-based class that holds the entire UI. All other widgets will be children of that and most will be children of whatever is defined as the "central widget" except for some modal dialogs and the decorations around the QMainWindow (menus, toolbars, dock widgets, etc.

    That is why in almost all of the Qt examples, the C++ main() entry point consists of the same few lines of code: create the QApplication instance, create the main window instance, show() the main window, and exec() the app. The rest of the UI is a tree of widgets that hang off the main window as children, children of children, and so on.

    For a case like your login scenario, you could go one of two ways: (1) Have a login dialog appear before the main window is shown to validate the user, and if successful launch the main window from that, or (2) follow the traditional approach of showing the main window, but then immediately post the login dialog. If login is successful, close the dialog, otherwise the dialog calls the main window's close() slot. It is probably easier to take the second approach.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 30th September 2013, 13:18
  2. open window in parent mdi
    By ShapeShiftme in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2011, 06:07
  3. Open QMainWindow to use xterm window as parent
    By muenalan in forum Qt Programming
    Replies: 0
    Last Post: 1st July 2010, 08:43
  4. Open subwindow from parent window ctor
    By olidem in forum Qt Programming
    Replies: 11
    Last Post: 13th May 2009, 14:52
  5. initialize child widgets within parent?
    By ucomesdag in forum Newbie
    Replies: 6
    Last Post: 6th June 2006, 08:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.