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. How to open MainWindow from Dialog

How to open MainWindow from Dialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.0k 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.
  • E Offline
    E Offline
    Echo773
    wrote on last edited by
    #1
    #include "options.h"
    #include "ui_options.h"
    #include "mainwindow.h"
    
    
    
    
    Options::Options(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Options)
    {
        ui->setupUi(this);
    }
    
    Options::~Options()
    {
        delete ui;
    }
    
    void Options::on_pushButton_2_clicked()
    {
        this->close();
        MainWindow w;
        w.show();
    }
    

    This executes without errors but does nothing, im trying to reopen the main window from a dialog window

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      MainWindow w;
      This constructs an entirely new MainWindow, puts it on the stack. Then 2 lines later the scope ends } and your main window is destroyed.

      You should rather pass a pointer to your actual MainWindow instance when creating the dialog, and then show it when pushButton2 is clicked.

      (Z(:^

      1 Reply Last reply
      3

      • Login

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