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. Is Stacked Widget the only option
Forum Updated to NodeBB v4.3 + New Features

Is Stacked Widget the only option

Scheduled Pinned Locked Moved General and Desktop
14 Posts 4 Posters 5.1k 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.
  • P Offline
    P Offline
    pragati
    wrote on last edited by
    #1

    Hi all,

    I am trying to build a project in which there are multiple screens. Functionality I am trying to put is to click a button and go back to next screen and then from any screen I can come back to the main menu...

    Now I am implementing this via. signal slot mechanism. The main priority is that every time I open any screen the previous should be hidden. Since for each screen I have different include and headers and form files, I am trying to create an instance of the class and then using it in signal slot mechanism...My code illustrates further....Here there are two screens (DMMMenu...the main menu and the Actual screen....I am able to go from main menu to Actual screen but cant come back to it.
    Do it is necessary to use Stackedwidget ?

    DMMMenu.h:
    @
    #ifndef DMM_H
    #define DMM_H
    #include <QtGui>
    #include <QWidget>
    #include "../../DMM/Include/Actual.h"
    #include "../../DMM/Include/DMM.h"
    class Actual;
    namespace Ui {

    class DMMMenu;

    }
    namespace DMM {

    class DMMMenu: public QWidget
    {
    Q_OBJECT

    public:

    explicit DMMMenu(QWidget *parent = 0);
    ~DMMMenu();

    public slots:

    void OnVoltageClicked();

    private:
    DMM::DMMMenu *MainWindow;
    Ui::DMMMenu *ui;
    Actual *Ac;

    };

    }

    #endif // DMM_H

    @

    DMM.cpp

    @

    include "../../Include/DMM.h"

    #include "../../DMM/Include/Actual.h"

    include "ui_DMMMenu.h"

    #include <QDateTime>

    namespace DMM
    {

    DMMMenu::DMMMenu(QWidget *parent) :
    QWidget(parent),

    ui(new ::Ui::DMMMenu)
    

    {

    ui->setupUi(this);
    Ac=new Actual;
    Ac->hide();
    connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(OnVoltageClicked()));
    

    //get current date
    QDate date = QDate::currentDate();
    QString dateString = date.toString();
    ui->Label_Date->setText(dateString);

    // get current time
    QTime time = QTime::currentTime();
    QString timeString = time.toString();
    ui->Label_Time->setText(timeString);

    }

    void DMMMenu::OnVoltageClicked()
    {
    Ac->show();
    this->hide();

    }

    DMMMenu::~DMMMenu()
    {

    }

    }

    @

    But when I am trying to do the same for Actual that is
    Actual.cpp

    @
    #include "../../DMM/Include/Actual.h"
    #include "../../DMM/Include/DMM.h"
    #include "ui_Actual.h"

    Actual::Actual(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Actual)
    {

    ui->setupUi(this);
    

    connect(ui->pushButton, SIGNAL clicked()),this, SLOT on_pushButton_clicked());

    home=new DMMMenu;
    home->hide();
    

    }

    Actual::~Actual()
    {
    delete ui;
    }

    void Actual::on_pushButton_clicked()
    {
    home->show();
    }

    @

    I get errors :
    /home/pragati/MultiFuncTester/Components/DMM/Build/../Source/Actual.cpp:18: error: invalid use of incomplete type 'struct DMMMenu'

    /home/pragati/MultiFuncTester/Components/DMM/Build/../../DMM/Include/Actual.h:7: error: forward declaration of 'struct DMMMenu'

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      You should use QStackedWidget and save yourself a bunch of effort.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pragati
        wrote on last edited by
        #3

        :).....but Chris.....Again I have to start from the scratch to use stackedwidget or I can somehow convert my ui into stackedwidget

        1 Reply Last reply
        0
        • V Offline
          V Offline
          veeraps
          wrote on last edited by
          #4

          Have you tried including DMMMenu.h in you Actual.cpp?
          @
          #include "../../DMM/Include/Actual.h
          #include "../../DMM/Include/DMM.h // Is this the header file that contains DMMMenu.h?
          #include "../../DMM/Include/DMMMenu.h
          #include "ui_Actual.h"
          @
          This is a cyclic dependency wherein your DMMMenu needs to know Actual and your Actual needs to know DMMMenu.

          Well, your requirement rightfully fits with/requires "QStackedWidget":http://doc-snapshot.qt-project.org/4.8/qstackedwidget.html - hence would suggest you to go thru it and use it - it reduces lot of complexity and pretty straight forward and simple to use it as well.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pragati
            wrote on last edited by
            #5

            yes the DMM.h is the one which contains dmmmenu definition.

            Actually we have to use these screens everywhere frequently in different subdirs which are part of this project so...stackwidget will not create a problem?

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6

              No. You can use as many instances of widgets as you like in as many places as you like. Some of those instances you can place in a QStackedWidget,

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pragati
                wrote on last edited by
                #7

                Will stacked widget create any problem in memory allocation or take more space ?

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  infoctopus
                  wrote on last edited by
                  #8

                  listen to people, QStackedWidget is your friend

                  Qt rulez

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pragati
                    wrote on last edited by
                    #9

                    @infoctopus.....:).......Yeah I want to....but some of my colleagues think that QStackedWidget will affect system's memory....So just to be assure and stay with QStackedWidget I need to be clear at this point of view....so guys help me out in deciding....please!!!!

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      pragati
                      wrote on last edited by
                      #10

                      My requirement is....I am going to have four different components in my project with lots of screens in it each and many will interact with each other....Its like a gui we have in our mobile...you can go back to main menu then switch to some other....the only difference is I am having different modes on which the device will work.....

                      So what you say what shall be the approach to achieve this kinda functionality

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        infoctopus
                        wrote on last edited by
                        #11

                        pragati, you either have your widgets (for "screens") in memory all the time (regardless of using QStackedWidget) OR you create/delete that widgets dynamically. I suggest to start with QStackedWidget and see if memory consumption is acceptable. If not, then create/delete objects when needed / not needed.

                        Qt rulez

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          pragati
                          wrote on last edited by
                          #12

                          :)

                          I am already facing a problem in connecting widgets.....I am able to go next screen from main menu but from that screen I am not able to come back again to main menu. It is not allowing me to create an instance of the main menu's class in the screen from which I have to go back
                          :(

                          1 Reply Last reply
                          0
                          • I Offline
                            I Offline
                            infoctopus
                            wrote on last edited by
                            #13

                            you can post a project illustrating the issue so people could help you in their little time

                            Qt rulez

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              pragati
                              wrote on last edited by
                              #14

                              Yeah I will do .....thanx anyways!!!

                              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