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. open multiple windows from a base window
Forum Updated to NodeBB v4.3 + New Features

open multiple windows from a base window

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 5.2k Views 1 Watching
  • 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.
  • collycrkC Offline
    collycrkC Offline
    collycrk
    wrote on last edited by
    #1

    I am building my first app in Qt5. I have a window that I open multiple windows from.
    I would like to keep more than on open from the base window.
    How is this done?
    Your help and time is appreciated.

    How to print a dialog in Qt seems to be beyond my comprehension. Would you like to teach me this one skill. If so, lets talk!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome
      well, if you use dialogs (for the extra windows)
      then you should read about modal and
      modeless dialogs.
      When modeless, you can open as many you like and still be able to click on main window.
      is that what you want?

      The big difference is how you call to "open" it.
      ->exec() // its blocks
      or
      ->show() // it shows dialog and execute next line ( not block)

      Beware the beginners trap:

      void OpenMyDialog() {
      QDialog mydia;
      mydia.show();
      }
      Since show don't block, it will exit the function and
      mydia will be deleted.

      So keep your dialogs instances in qmainwindow or use pointers.

      1 Reply Last reply
      0
      • collycrkC Offline
        collycrkC Offline
        collycrk
        wrote on last edited by
        #3

        Thanks mrjj for your response.
        This is the code I am using from the 'dashboard' module.

        Some more information on my situation.
        I have studied modal and modeless as you suggested.
        I have created a 'dashboard' that stays up and it is modal. From this 'dashboard' all apps are opened.
        When an app is set to modeless and is selected it appears for a mil sec and disappears.
        I have not been able to find the code that will keep modeless windows up.
        This is the code I am using to launch the app from the 'dashboard':
        ViewReceipt viewreceipt;
        viewreceipt.setModal(false);
        viewreceipt.show();

        Thanks again for your help!

        How to print a dialog in Qt seems to be beyond my comprehension. Would you like to teach me this one skill. If so, lets talk!

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          hi
          that kinda look as beginners trap :)
          if this is in a function

          ViewReceipt viewreceipt;
          viewreceipt.setModal(false);
          viewreceipt.show();
          ----- here viewreceipt is deleted and closed

          so
          ViewReceipt* = new viewreceipt;
          viewreceipt->setModal(false);
          viewreceipt->show();

          works, but you will have mem leak.
          so its better to put ViewReceipt viewreceipt; in the base window (in .,h , in the class)
          as a class member and then just call show() when needed.

          1 Reply Last reply
          0
          • collycrkC Offline
            collycrkC Offline
            collycrk
            wrote on last edited by
            #5

            This is what I found after being pointed to the correct path by mrjj, thanks so much sir.
            basewin_dialog.cpp
            included the modelessdialog.h file to basewin_dialog.cpp

            added this code:
            // modeless heap memory uses arrow pointer
            pmodeless =new ModelessDialog(this);
            pmodeless->show();

            basewin_dialog.h
            added in the private: section:
            ModelessDialog *pmodeless;

            modeless_dialog.cpp
            now opens and the basewin_dialog is released
            and now there can be mulitple windows opened

            Works fine every time.

            The only thing left is the problem of memory leak.
            Will the exit close (this->close();) of the modeless win take care of memory leaks.
            Or does it need to be dealt with another way?

            How to print a dialog in Qt seems to be beyond my comprehension. Would you like to teach me this one skill. If so, lets talk!

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              ++The only thing left is the problem of memory leak.
              ++Will the exit close (this->close();) of the modeless win take care of memory leaks.
              nope. all you NEW must be deleted unless you give it to a parent that owns it.
              For dialogs, you should delete them yourself.

              Other options is to use
              setAttribute(Qt::WA_DeleteOnClose);
              (in dialog)
              that means it cleans up when closed but be sure you then new it again before
              calling show() else u crash.

              so since u have ModelessDialog *pmodeless; in private section.
              I suggest just to new in basewin_dialog constructor and
              delete in basewin_dialog destructor so that class will clean up.
              will be the easiest. :)

              But actually , you don't have to new them
              you can have (in class private , NOT in function :)
              ModelessDialog pmodeless; // not pointer
              and just call
              pmodeless.show();
              notice that its "." and not ->
              Then its deleted when basewin_dialog is.

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved