Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How to swap windows?

    General and Desktop
    4
    5
    903
    Loading More Posts
    • 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
      RayBradbury last edited by

      This is a very simple question that I can't quite get my head around...

      If I click a button in the mainwindow it will hide mainwindow then make a NewWindow and show it. If I click on NewWindow it will hide NewWindow and then unhide mainwindow....

      Question is, how do I get NewWindow (which is a child of mainwindow, I think?) to access mainwindow and tell it to do something?

      @#include "mainwindow.h"
      #include "ui_mainwindow.h"

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

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

      void MainWindow::on_Button_ToNew_clicked()
      {
      this->hide();
      Instance1_NewWindow = new NewWindow(this);
      Instance1_NewWindow->show();
      }
      @

      No idea where to start in the NewWindow

      @#include "newwindow.h"
      #include "ui_newwindow.h"

      #include "mainwindow.h"

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

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

      void NewWindow::on_Button_ToMain_clicked()
      {

      }
      @

      1 Reply Last reply Reply Quote 0
      • Q
        qxoz last edited by

        Welcome to DevNet.

        "Signals and slots":http://qt-project.org/doc/qt-5/signalsandslots.html will help you.

        1 Reply Last reply Reply Quote 0
        • A
          ankursaxena last edited by

          U can do it using qsharedmemory .

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            Why use something like QSharedMemory for that task ? Signals and Slots like qxoz suggested is the right way

            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 Reply Quote 0
            • A
              ankursaxena last edited by

              Ohk. I misunderstood the question. i understood that there should be only a single instance. Probably i haven't read out it clearly. sorry for inconvenience .

              1 Reply Last reply Reply Quote 0
              • First post
                Last post