Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am able to do it well. I just give the code for anyone who need this. I have a window called <code>MainWindow</code> and a <code>NewWindow</code>. I have a button in <code>Mainwindow</code> called <code>mMyButton</code>. <code>mainwindow.h</code> is as follows.</p> <pre><code>#ifndef MAINWINDOW_H #define MAINWINDOW_H #include &lt;QMainWindow&gt; //added #include"newwindow.h" namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); //added public slots: void openNewWindow(); //added name of the new window is NewWindow private: NewWindow *mMyNewWindow; private: Ui::MainWindow *ui; private slots: void on_mMyButton_clicked(); }; #endif // MAINWINDOW_H </code></pre> <p>My newwindow.h is as follows.</p> <pre><code>#ifndef NEWWINDOW_H #define NEWWINDOW_H #include &lt;QMainWindow&gt; namespace Ui { class NewWindow; } class NewWindow : public QMainWindow { Q_OBJECT public: explicit NewWindow(QWidget *parent = 0); ~NewWindow(); private: Ui::NewWindow *ui; }; #endif // NEWWINDOW_H </code></pre> <p>My mainwindow.cpp is as follows.</p> <pre><code>#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui-&gt;setupUi(this); //Added connect(ui-&gt;mMyButton, SIGNAL(click()), this, SLOT(openNewWindow())); } MainWindow::~MainWindow() { delete ui; } void MainWindow::openNewWindow() { mMyNewWindow = new NewWindow(); mMyNewWindow-&gt;show(); } void MainWindow::on_mMyButton_clicked() { openNewWindow(); } </code></pre> <p>My newwindow.cpp,</p> <pre><code>#include "newwindow.h" #include "ui_newwindow.h" NewWindow::NewWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::NewWindow) { ui-&gt;setupUi(this); } NewWindow::~NewWindow() { delete ui; } </code></pre> <p>My main.cpp as,</p> <pre><code> #include &lt;QtGui/QApplication&gt; #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } </code></pre> <p>Thanks for all the information. And enjoy the programming with Qt.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload