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
Forum Updated to NodeBB v4.3 + New Features

Communication between QWidgets in Stacked Window

Scheduled Pinned Locked Moved Solved General and Desktop
stackedwidgetsignals&slots
13 Posts 3 Posters 4.8k 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.
  • lagodolioL lagodolio

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

    RatzzR Offline
    RatzzR Offline
    Ratzz
    wrote on last edited by
    #4

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

    --Alles ist gut.

    lagodolioL 1 Reply Last reply
    0
    • RatzzR Ratzz

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

      lagodolioL Offline
      lagodolioL Offline
      lagodolio
      wrote on 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

      RatzzR 1 Reply Last reply
      0
      • lagodolioL lagodolio

        @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

        RatzzR Offline
        RatzzR Offline
        Ratzz
        wrote on 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
        • lagodolioL Offline
          lagodolioL Offline
          lagodolio
          wrote on 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

          mrjjM 1 Reply Last reply
          0
          • lagodolioL lagodolio

            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

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on 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
            • lagodolioL Offline
              lagodolioL Offline
              lagodolio
              wrote on 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
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on 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
                • lagodolioL Offline
                  lagodolioL Offline
                  lagodolio
                  wrote on 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

                  mrjjM 1 Reply Last reply
                  0
                  • lagodolioL lagodolio

                    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

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 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
                    • lagodolioL Offline
                      lagodolioL Offline
                      lagodolio
                      wrote on last edited by
                      #13

                      Perfect !

                      1 Reply Last reply
                      0

                      • Login

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