Results 1 to 11 of 11

Thread: Dynamically Loading a QMainWindow?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2006
    Location
    Seattle
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamically Loading a QMainWindow?

    Good point.

    I changed the parent class to QWidget, but like my story goes, it still doesn't work.

    Since this is no longer a QMainWindow subclass, the setCentralWidget is no longer available. With or without the original layout code, my GUI isn't showing up. One noted difference though, the blank form that shows up with the layout code is small, slightly larger than the window decroations. Removing the layout code creates a huge window that feels close to a main window...I swear the solution must be near.

    As a side, how do you experts start your Qt applications? This seems like a natural way to do it; it's similar to how I've done this type of thing in Gtk.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Dynamically Loading a QMainWindow?

    Quote Originally Posted by natron
    Since this is no longer a QMainWindow subclass, the setCentralWidget is no longer available.
    This time you try to put QMainWindow on QWidget.

    As you can see:
    Qt Code:
    1. QMainWindow::QMainWindow(QWidget *parent, Qt::WFlags flags)
    2. : QWidget(*(new QMainWindowPrivate()), parent, flags | Qt::Window /* <- note this flag */ )
    3. {
    4. d_func()->init();
    5. }
    To copy to clipboard, switch view to plain text mode 
    QMainWindow is always a top level window. You have to either change your .ui file or use a different approach.

    As a side, how do you experts start your Qt applications?
    I prefer to use uic instead of QUiLoader. If you store .ui files in resources it doesn't make much difference, except that the code generated by uic is smaller and runs faster.

  3. The following user says thank you to jacek for this useful post:

    natron (20th July 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamically Loading a QMainWindow?

    Quote Originally Posted by natron
    Since this is no longer a QMainWindow subclass, the setCentralWidget is no longer available.
    Maybe you should create an instance of QMainWindow and then use setCentralWidget to set your widget as its main part? I mean something like:

    Qt Code:
    1. int main(int argc, char **argv){
    2. QApplication app(argc, argv);
    3. // ...
    4. mw.setCentralWidget(createYourWidgetHere);
    5. //...
    6. mw.show();
    7. return app.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 


    As a side, how do you experts start your Qt applications?
    I don't exactly understand what you mean... How do we execute applications or how do we implement them?

    If the former then either from the command line, KDevelop or by clicking on an icon in Konqueror. I think all people do it in one of these ways...

    If the latter, then I start by writing main.cpp with contents such as the one above, then implement my main ui, subclass it to create the main window class and then I check if it works fine. Afterwards I begin to implement the functionality.

    And I don't use dynamically loaded forms

  5. The following user says thank you to wysota for this useful post:

    natron (20th July 2006)

  6. #4
    Join Date
    Jul 2006
    Location
    Seattle
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamically Loading a QMainWindow?

    Hey, thanks you two for your help. I got it working so far.

    I realized my blunder - I basically had the right code, just in the wrong place.

    My main now loads the .ui file, followed by
    Qt Code:
    1. MainForm mfMain;
    2. mfMain.setCentralWidget(formWidget);
    To copy to clipboard, switch view to plain text mode 

    where the ctor for MainForm goes like so
    Qt Code:
    1. MainForm::MainForm(QWidget *parent) : QMainWindow(parent)
    2. {
    3. //...
    4. }
    To copy to clipboard, switch view to plain text mode 

    This makes a lot of sense too; it works like wysota's post above.

    Any idea why Gtk's (using Glade) method of interface design explicitly promotes dynamic interface loading, while in Qt land the paradigm focuses on the static method? I can see advantages and restrictions in both, but neither seems clearly better.

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamically Loading a QMainWindow?

    Quote Originally Posted by natron
    Any idea why Gtk's (using Glade) method of interface design explicitly promotes dynamic interface loading, while in Qt land the paradigm focuses on the static method? I can see advantages and restrictions in both, but neither seems clearly better.
    <flame mode>
    Maybe because Qt is better?
    </flame mode>

    Qt is object oriented and focuses on using classes, also for things like the GUI, whereas Gtk is not object oriented and doesn't care about classes, so it doesn't matter where it creates its bunch of variables responsible for controlling the user interface. Of course that's my personal opinion

Similar Threads

  1. Switching static to dynamic ui loading
    By s_a_white in forum Newbie
    Replies: 4
    Last Post: 26th June 2006, 15:57
  2. Insert separate QToolBar into QMainWindow
    By YuriyRusinov in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 10:37
  3. Replies: 18
    Last Post: 22nd February 2006, 20:51
  4. QSA: loading scripts at runtime
    By seneca in forum Qt Programming
    Replies: 0
    Last Post: 15th February 2006, 15:19

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.