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. Multiple Windows Desktop application
Forum Update on Monday, May 27th 2025

Multiple Windows Desktop application

Scheduled Pinned Locked Moved General and Desktop
13 Posts 5 Posters 23.1k 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.
  • R Offline
    R Offline
    rufy23
    wrote on 23 Jan 2013, 22:12 last edited by
    #1

    Hi to everybody,
    how the title describes I'm trying to program a Desktop Application with qt libraries. I use the qt designer in Visual Studio 2010, so I'm programming in c++. My problem is to set multiple windows at the same time in a way that they could interact together. For example I need a window with more pushbuttoms and clicking on them i need to activate a signal which hides the current window and shows another window. How could I do?
    Thanks for the answers

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on 23 Jan 2013, 22:20 last edited by
      #2

      Create multiple top-level windows and connect them as required using signals and slots. If you are going to have some sort of permanent "switchboard" window then make that the one that your program's main() creates, and have it create/show/hide the others as required.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rufy23
        wrote on 23 Jan 2013, 22:35 last edited by
        #3

        If i create multiple top-level windows I can't connect them using signals and slots becouse I must save them on different files .ui and in qt designer I can't connect them manually becouse signals and slots are depending on their particolar class.
        How can I use the way your are suggest me with qt designer?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Code_ReaQtor
          wrote on 24 Jan 2013, 05:04 last edited by
          #4

          try "IPC":http://doc.qt.digia.com/main-snapshot/ipc.html

          Please visit my open-source projects at https://github.com/Code-ReaQtor.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on 24 Jan 2013, 11:59 last edited by
            #5

            IPC is only necessary if the windows are controlled by different processes. I doubt that is what rufy23 wants to do.

            rufy23: Of course you can use signals and slots between different UIs. You just can not set them in the designer, but are free to add them from your code later.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Code_ReaQtor
              wrote on 24 Jan 2013, 12:45 last edited by
              #6

              bq. hides the current window and shows another window

              Sorry, did I mistakenly interpreted this as independent windows? My bad.

              This "link":http://doc.qt.digia.com/qt/tools-customtypesending.html might be a little different but the theory is the same, I think.

              Please visit my open-source projects at https://github.com/Code-ReaQtor.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                rufy23
                wrote on 24 Jan 2013, 22:03 last edited by
                #7

                Thank you, I understand what you say. Now I ask another help: is there an easier and faster way to do this? I have to do an application with a lot of windows linked together and I think it is not so easy to do without the qt designer, also becouse I always used it to do everything.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rufy23
                  wrote on 25 Jan 2013, 14:56 last edited by
                  #8

                  For example is there a way to melt a qmainwindow with a qstackedwidget in the designer? I think it could resolve my problem, isn't it?

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on 25 Jan 2013, 15:55 last edited by
                    #9

                    No, it is not. Qt Designer is a great tool for designing widgets, but it is not a complete visual programming environment. You still need to write code. If you try to force everything into one single designer file, you're going to end up with a single huge class. That is not very maintainable or reusable.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      rufy23
                      wrote on 25 Jan 2013, 16:54 last edited by
                      #10

                      Ok, but I can't understand just one thing. If I create a lot of classes, one for each window for example, how can I connect them in this way? I have some difficulties to create signals which are referred to different objects.
                      For Example I create a class for the first window and another class for the second. I have for each of the both three files (first window has: ui_firstwindow.h firstwindow.h firstwindow.cpp and the same thing for the second window). In first window there is a pushbutton called next which hides first window and shows second window. In second window there is a pushbutton called previous which hides second window and shows first window. For the next button where do I have to put the connect?I have this problem becouse I can't understand how to connect different objects.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        ChrisW67
                        wrote on 29 Jan 2013, 01:47 last edited by
                        #11

                        Define an exposed signal in your window class:
                        @
                        class Window1: public QWidget
                        {
                        ...
                        signals:
                        void showOtherWindow();
                        };
                        @

                        Connect the push button to your own hide() slot and also emit the signal:
                        @
                        Window1::Window1(QWidget *p = 0):
                        QWidget(p), ui(new Ui::Window1)
                        {
                        ui->setupUi(this);
                        connect(ui->pushButton, SIGNAL(clicked()), SLOT(hide()));
                        connect(ui->pushButton, SIGNAL(clicked()), SIGNAL(showOtherWindow()));
                        }
                        @
                        You can connect a signal to another signal and arrival of the first will trigger emit on the second. Window2 looks the same. In your main:
                        @
                        int main(int argc, char **argv)
                        {
                        QApplication app(argc, argv);

                        Window1 w1;
                        Window2 w2;
                        
                        QObject::connect(&w1, SIGNAL(showOtherWindow()), &w2, SLOT(show()));
                        QObject::connect(&w2, SIGNAL(showOtherWindow()), &w1, SLOT(show()));
                        w1.show();  // only show one of them to start
                        
                        return app.exec();
                        

                        }
                        @

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          rufy23
                          wrote on 29 Jan 2013, 09:58 last edited by
                          #12

                          Thank you very much, it is very usefull. Just another little thing, not very important. If I build the window with the designer, can I copy the code generated and use it in my application, or is there something more or something less?

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on 29 Jan 2013, 10:20 last edited by
                            #13

                            Don't copy the generated code. Include it instead and use it that way.

                            1 Reply Last reply
                            0

                            1/13

                            23 Jan 2013, 22:12

                            • Login

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