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. Using a push button to reopen my main window.
Forum Updated to NodeBB v4.3 + New Features

Using a push button to reopen my main window.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.3k Views 2 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.
  • C Offline
    C Offline
    cdbean04
    wrote on 8 Jun 2015, 20:51 last edited by
    #1

    I am creating a UI that has one main pages and two subpages. When going to the sub page I have the main page closing, I would like to then open the main page again on clicking a "back" button that I created. I keep getting an error that says modeselect does not name a type. Mode select is the page I am trying to return to. I am only trying to get the back button on the page called noheatmode to work right now. Below are the two .h files for the pages and the noheatmode.cpp

    modeselect.h file
    #ifndef MODESLECT_H
    #define MODESLECT_H

    #include <QMainWindow>
    #include "noheatmode.h"
    #include "heatmode.h"

    namespace Ui {
    class modeselect;
    }

    class modeselect : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit modeselect(QWidget *parent = 0);
    ~modeselect();

    private slots:
    void on_noHeatModeButton_clicked();

    void on_heatModeButton_clicked();
    

    private:
    Ui::modeselect *ui;
    noheatmode *noHeatMode;
    heatmode *heatMode;

    };

    #endif // MODESLECT_H

    noheatmode.h file

    #ifndef NOHEATMODE_H
    #define NOHEATMODE_H

    #include <QWidget>
    #include "modeselect.h"

    namespace Ui {
    class noheatmode;
    }

    class noheatmode : public QWidget
    {
    Q_OBJECT

    public:
    explicit noheatmode(QWidget *parent = 0);
    ~noheatmode();

    private slots:
    void on_noHeatModeBack_clicked();

    private:
    Ui::noheatmode *ui;
    modeselect *modeSelect;
    };

    #endif // NOHEATMODE_H

    noheatmode.cpp

    #include "modeselect.h"
    #include "noheatmode.h"
    #include "ui_noheatmode.h"

    noheatmode::noheatmode(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::noheatmode)
    {
    ui->setupUi(this);
    }

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

    void noheatmode::on_noHeatModeBack_clicked()
    {
    modeSelect =new modeselect;
    modeSelect ->show();
    close();
    }

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Jun 2015, 21:04 last edited by
      #2

      Hi and welcome to devnet,

      Don't you have circular dependencies issues ?

      In any case, your current design is wrong, you are trying to recreate each widget each time you go from one to the other and you are creating memory leaks.

      You should take a look at QStackedWidget/Layout in order to have a proper "widget switcher"

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cdbean04
        wrote on 8 Jun 2015, 21:16 last edited by
        #3

        Thanks I will look into it. I was concerned that stacking pages on top of each other may add up to some issues, so i thought I would try this approach which apparently does not work.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 8 Jun 2015, 21:24 last edited by
          #4

          A QStackedWidget is really just that: you show one widget at a time and switch to the one you want/need when you want.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          1/4

          8 Jun 2015, 20:51

          • Login

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