Qt Creator -main window and second window

how do you hide the main Window after opening the second Window?Also, when the second Window is closed by the user, how can the main window reappear?

these are the codes I have so far.
I have an error that says ERROR:no matching constructor for initialization 'Dialog'...this is the only error I have. Please help me fix it.


mainwindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 #ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    
public:
    void show();



private slots:
    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H 


secwindow.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef SECWINDOW_H
#define SECWINDOW_H

#include <QDialog>

namespace Ui {
class SecWindow;
}

class SecWindow : public QDialog
{
    Q_OBJECT

public:
    explicit SecWindow(QWidget *parent = nullptr);
    ~SecWindow();


private:
    Ui::SecWindow *ui;
};

class Dialog : public QDialog
{
public:
    Dialog();

private:
    Dialog *dialog;

};


#endif // SECWINDOW_H 



Source Code

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    a.setQuitOnLastWindowClosed(false);
    MainWindow w;
    w.show();

    return a.exec();
}



mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QPixmap>
#include "secwindow.h"
#include <QDialog>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QPixmap pix("C:/Users/Charlene/Downloads/Charlene Back-up/MAPUA/2nd Term/Object Oriented Programming/GOW-Gui/GOW-GUI/intro pic/intro.png");
    ui->label->setPixmap(pix.scaled(230,250,Qt::KeepAspectRatio));

   // QWidget *wdg = new QWidget;
    //wdg->show();
    //hide();
}

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

void MainWindow::on_pushButton_clicked() // Modal approach..mainwindow cannot be moved when secwindow is displayed.
{
    SecWindow secwindow;
    secwindow.setModal(true); //it'll set the secwindow
    secwindow.exec(); //shows secwindow when button is pressed
}

void MainWindow::show()
{
    Dialog *dialog = new Dialog(this); //ERROR: no matching constructor for initialization of 'Dialog'
    connect(dialog, SIGNAL(accepted()), this, SLOT(show()));
    connect(dialog, SIGNAL(rejected()), this, SLOT(show()));
    dialog->show();
    hide();
};



secwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "secwindow.h"
#include "ui_secwindow.h"
#include <QPixmap>

SecWindow::SecWindow(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SecWindow)
{
    ui->setupUi(this);
    QPixmap pix("C:/Users/Charlene/Downloads/Charlene Back-up/MAPUA/2nd Term/Object Oriented Programming/GOW-Gui/GOW-GUI/images/102.gif");
    ui->label_2 ->setPixmap(pix.scaled(100,95, Qt::KeepAspectRatio));
}

SecWindow::~SecWindow()
{
    delete ui;
}
Last edited on
Topic archived. No new replies allowed.