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. QMainWindow Issue
Qt 6.11 is out! See what's new in the release blog

QMainWindow Issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 838 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.
  • QT_QT_QTQ Offline
    QT_QT_QTQ Offline
    QT_QT_QT
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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)

      1 Reply Last reply
      0

      • Login

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