QMainWindow Issue



  • I have an issue over here, this is regarding to main window . Supposedly in the main window has a push button and that button will lead us to a new window . In other words, at the moment the user pressed the button , the user will see a new main window , and the previous window will be close. Below code keep providing these error : Ui::newwindow:no appropriate default constructor available, use of defined type 'Ui::newwindow' and left of '->setupUI' must point to class/struct/union/generic type;

    ***MainWindow.h***
    
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include "newwindow.h"
    #include <QWidget>
    
    namespace Ui {
    class MainWindow;
    }
    
    
    class MainWindow : public QMainWindow
    {
         Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    private slots:
        void on_pushButton_clicked();
    
        void on_pushButton_2_clicked();
    
        void on_pushButton_3_clicked();
    
        void on_pushButton_4_clicked();
    
        void openNewWindow();
    
    private slots:
        void on_pushButton_5_clicked();
    
    private:
        Ui::MainWindow *ui;
    private:
        newwindow *MyNewWindow;
    
    
    };
    
    #endif // MAINWINDOW_H
    
    
    ***newwindow.h***
    #ifndef NEWWINDOW_H
    #define NEWWINDOW_H
    
    #include <QMainWindow>
    
    namespace Ui {
        class newwindow;
    }
    
    class newwindow : public QMainWindow
    {
        Q_OBJECT
    public:
        newwindow();
        explicit newwindow(QWidget *parent = 0);
        ~newwindow();
     private:
        Ui::newwindow *ui;
    };
    
    #endif // NEWWINDOW_H
    
    
    
    ***mainwindow.cpp***
    
    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QByteArray>
    #include <QProcess>
    #include <Windows.h>
    #include <iostream>
    #include <string>
    #include <cstdlib>
    #include <stdlib.h>
    #include <QDebug>
    #include <QString>
    #include <QMessageBox>
    #include "newwindow.h"
    #include <QWidget>
    
    using namespace std;
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        connect(ui->pushButton_5,SIGNAL(click()),this, SLOT (openNewWindow()));
     }
    
    
    MainWindow::~MainWindow()
    {
        delete ui;
    
    
    }
    
    void MainWindow ::openNewWindow()
    {
        MyNewWindow = new newwindow();
        MyNewWindow-> show();
    }
    
    void MainWindow::on_pushButton_5_clicked()
    {
        openNewWindow();
    }
    
    
    ***newwindow.cpp***
    
    
    #include "newwindow.h"
    #include "ui_mainwindow.h"
    
    #include <QMainWindow>
    
    
    newwindow::newwindow(QWidget *parent):QMainWindow(parent),
        ui(new Ui::newwindow)
    {
        ui->setupUi(this);
    }
    
    newwindow::~newwindow()
    {
        delete ui;
    }
    
    

    Some one from here please tell what is problem that i m facing now . please....... I dont understand why i keep getting the error . Thank you


  • Qt Champions 2016

    Did you add this newwindow , via
    File->New->Qt->QtDesigner Form Class
    and then QMainwindow?

    Also having multiple Main Windows is a rare design.
    Are you sure this is how u want ? the user will see the window close and new one come.
    Like app crashed and restarted.
    If you need a design where u have pages ,
    the QStackwidget is much better. (IMHO)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.