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. Communication between QWidgets in Stacked Window
QtWS25 Last Chance

Communication between QWidgets in Stacked Window

Scheduled Pinned Locked Moved Solved General and Desktop
stackedwidgetsignals&slots
13 Posts 3 Posters 4.6k 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.
  • L Offline
    L Offline
    lagodolio
    wrote on 27 May 2016, 08:12 last edited by A Former User
    #1

    Hello,
    I'm new in Qt and I have a trouble that stop me for a week...Ok it's probably a stupid question but I tried different ways with no success.
    I have to assemble some QWidget created by Qt Creator, the first one ( we call it "pag1", it is composed by "pag1.ui", "pag1.h" and "pag1.cpp") shows a window with some text,controls and a button "Go to Page 2", the second qWidget has text and controls.
    Finally, we have a main window (MainWindow) with controls and a Stacked Window. By "promote" function I linked pag1 widget to Stacked Window first page (Page1) and pag2 to the second one (Page2).
    I have no problem if I call pag1 and pag2 by main window, but I'm no able to make button "Go to Page 2" ordering Mainwindow to erase Page1 and show Page2.
    Any solutions? I tried signals and slot (I think it's the correct way), but pag1 doesn't see pag2...
    Thanks for all and good days!
    Mario

    R 1 Reply Last reply 27 May 2016, 10:49
    0
    • L lagodolio
      27 May 2016, 08:12

      Hello,
      I'm new in Qt and I have a trouble that stop me for a week...Ok it's probably a stupid question but I tried different ways with no success.
      I have to assemble some QWidget created by Qt Creator, the first one ( we call it "pag1", it is composed by "pag1.ui", "pag1.h" and "pag1.cpp") shows a window with some text,controls and a button "Go to Page 2", the second qWidget has text and controls.
      Finally, we have a main window (MainWindow) with controls and a Stacked Window. By "promote" function I linked pag1 widget to Stacked Window first page (Page1) and pag2 to the second one (Page2).
      I have no problem if I call pag1 and pag2 by main window, but I'm no able to make button "Go to Page 2" ordering Mainwindow to erase Page1 and show Page2.
      Any solutions? I tried signals and slot (I think it's the correct way), but pag1 doesn't see pag2...
      Thanks for all and good days!
      Mario

      R Offline
      R Offline
      Ratzz
      wrote on 27 May 2016, 10:49 last edited by
      #2

      @lagodolio
      Have you created pages using QStackedWidget http://doc.qt.io/qt-4.8/qstackedwidget.html ?

      --Alles ist gut.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lagodolio
        wrote on 27 May 2016, 13:49 last edited by A Former User
        #3

        Yes, I created a QStackedWidget by Qt Creator. I can see it in mainwindows.ui, but it is not editable...

        R 1 Reply Last reply 28 May 2016, 06:14
        0
        • L lagodolio
          27 May 2016, 13:49

          Yes, I created a QStackedWidget by Qt Creator. I can see it in mainwindows.ui, but it is not editable...

          R Offline
          R Offline
          Ratzz
          wrote on 28 May 2016, 06:14 last edited by
          #4

          @lagodolio
          can you create a minimal sample to reproduce it?

          --Alles ist gut.

          L 1 Reply Last reply 28 May 2016, 07:24
          0
          • R Ratzz
            28 May 2016, 06:14

            @lagodolio
            can you create a minimal sample to reproduce it?

            L Offline
            L Offline
            lagodolio
            wrote on 28 May 2016, 07:24 last edited by A Former User
            #5

            @Ratzz Yes, of course.
            As my project, this sample is created by Qt Creator. The program is called by inter_comm.pro.
            Thank you in advance and have a nice weekend,
            Mario

            This is the zip file - fully editable

            R 1 Reply Last reply 28 May 2016, 07:33
            0
            • L lagodolio
              28 May 2016, 07:24

              @Ratzz Yes, of course.
              As my project, this sample is created by Qt Creator. The program is called by inter_comm.pro.
              Thank you in advance and have a nice weekend,
              Mario

              This is the zip file - fully editable

              R Offline
              R Offline
              Ratzz
              wrote on 28 May 2016, 07:33 last edited by Ratzz
              #6

              @lagodolio
              You need not create two new pages separately rather you can use 2 stack pages to achieve this.

              --Alles ist gut.

              1 Reply Last reply
              2
              • L Offline
                L Offline
                lagodolio
                wrote on 28 May 2016, 19:09 last edited by
                #7

                Hello Ratzz and thanks for your support.
                My problem is that every page is quite complex ( data analysis and processing / system control /database management ). A friend of mine and I are creating autonomous programs so we are able to work quite independently.
                Thanks to qt library we are going to assemble those parts in GUI style ( we initially used Processing, but we abandon it because of performance).
                Those programs (they appear as stacked pages) have to call each other, just like "pag1" of my little sample calls pag2.
                Thank you and happy weekend to all the forum!
                Mario

                M 1 Reply Last reply 28 May 2016, 20:17
                0
                • L lagodolio
                  28 May 2016, 19:09

                  Hello Ratzz and thanks for your support.
                  My problem is that every page is quite complex ( data analysis and processing / system control /database management ). A friend of mine and I are creating autonomous programs so we are able to work quite independently.
                  Thanks to qt library we are going to assemble those parts in GUI style ( we initially used Processing, but we abandon it because of performance).
                  Those programs (they appear as stacked pages) have to call each other, just like "pag1" of my little sample calls pag2.
                  Thank you and happy weekend to all the forum!
                  Mario

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 28 May 2016, 20:17 last edited by
                  #8

                  @lagodolio
                  hi
                  Are you asking how you can access widgets from one page to another page ?

                  private:
                  Ui::pag1 *ui;

                  or what do you mean by
                  "..have to call each other," ?

                  If each page is a module, you should define public signals for the processing result.
                  You can then connect page1 to page2 for piping.

                  in your sample the pages are QMainWindows.
                  you put them in stacked widget??

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lagodolio
                    wrote on 28 May 2016, 21:30 last edited by
                    #9

                    Sorry , to be honest "..have to call each other" is not very clear... It means that some widgets promoted in stacked windows have a button that call another widget in stacked windows.
                    My sample pag1.cpp should be something as:

                    // /* pag1.cpp*/
                    
                    #include "pag1.h"
                    #include "ui_pag1.h"
                    
                    pag1::pag1(QWidget *parent) :
                        QMainWindow(parent),
                        ui(new Ui::pag1)
                    {
                        ui->setupUi(this);
                    }
                    
                    pag1::~pag1()
                    {
                        delete ui;
                    }
                    
                    void pag1::on_pushButton_clicked()
                    {
                      /********************************************
                        Do something as:
                        ui->pag1->>setHidden(true);
                        ui->pag2>>setHidden(false);
                    **********************************************/    
                      
                    }
                    
                    
                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 29 May 2016, 09:38 last edited by mrjj
                      #10

                      Hi
                      you cannot talk to other pages from a page
                      that would become spaghetti code if all pages must know all other pages.

                      What you can do is to to let mainwindow control the pages.
                      since it already have the stacked widget.

                      So you use signals and slot to make this happen.

                      I have altered your sample to do this:
                      https://www.dropbox.com/s/elj1zqu9ts73hur/stk.zip?dl=0

                      The change are:
                      Define signal for page
                      emit ShowPage( 1 ); from button

                      in mainwindow
                      make slot
                      connect( ui->page, SIGNAL(ShowPage(int)), this, SLOT(ShowPage(int)) );

                      and

                      // this is called from pages via signal
                      void MainWindow::ShowPage(int index) {
                      qDebug() << "show page request: " << index;
                      // do the actual switch
                      ui->stackedWidget->setCurrentIndex(index);
                      }

                      Now a page can ask to switch to other page.
                      You can do this for any other function or info you want between pages.

                      1 Reply Last reply
                      1
                      • L Offline
                        L Offline
                        lagodolio
                        wrote on 29 May 2016, 12:34 last edited by
                        #11

                        Wow, it works!
                        You are right, this approach is more efficient ( and elegant too) rather then my code
                        Thanks for all, now I can start working ( after a week ...).
                        Have a nice days.
                        Mario

                        M 1 Reply Last reply 29 May 2016, 13:43
                        0
                        • L lagodolio
                          29 May 2016, 12:34

                          Wow, it works!
                          You are right, this approach is more efficient ( and elegant too) rather then my code
                          Thanks for all, now I can start working ( after a week ...).
                          Have a nice days.
                          Mario

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 29 May 2016, 13:43 last edited by
                          #12

                          @lagodolio
                          super :)

                          just a note:
                          If you design a base class for pages and inherit from that, you can
                          just define the signals for showpage, and what else you need , in
                          this base class and all pages can be hooked up pr default.

                          1 Reply Last reply
                          0
                          • L Offline
                            L Offline
                            lagodolio
                            wrote on 29 May 2016, 14:42 last edited by
                            #13

                            Perfect !

                            1 Reply Last reply
                            0

                            5/13

                            28 May 2016, 07:24

                            topic:navigator.unread, 8
                            • Login

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