Reopen MainWindow
-
Hello,
I made two mainwindow- mainwindow.h & cpp
- playlist.h & cpp
when i clicked open playlist button
close mainwindow (1) and open playlist (2)but i don't know how to reopen mainwindow from playlist
how to reopen ?#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QFileSystemModel> #include <QDebug> #include <QMediaPlayer> #include "playlist.h" #include "library.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); void show_main(); private slots: void on_treeView_clicked(const QModelIndex &index); void on_progressSlider_sliderMoved(int position); void on_volumeSlider_sliderMoved(int position); void on_startBtn_clicked(); void on_stopBtn_clicked(); void on_positionChanged(int position); void on_durationChanged(int position); void on_playlistBtn_clicked(); void on_libraryBtn_clicked(); private: Ui::MainWindow *ui; QFileSystemModel *dirmodel; QFileSystemModel *filemodel; QMediaPlayer *player; QString abPath; PlayList *plyList; Library *lib; }; #endif // MAINWINDOW_H -------- #ifndef PLAYLIST_H #define PLAYLIST_H #include <QMainWindow> #include "ui_mainwindow.h" namespace Ui { class PlayList; } class PlayList : public QMainWindow { Q_OBJECT public: explicit PlayList(QWidget *parent = nullptr); ~PlayList(); private slots: void on_playBtn_clicked(); void on_stopBtn_clicked(); void on_progressSlider_valueChanged(int value); void on_volumeSlider_valueChanged(int value); void on_mainBtn_clicked(); void on_libBtn_clicked(); void on_exitBtn_clicked(); private: Ui::MainWindow *mainPtr; Ui::PlayList *ui; }; #endif // PLAYLIST_H
-
@vel1024 Call https://doc.qt.io/qt-5/qwidget.html#show
Create an instance of it if already destroyed before calling show().
But why do you want to have two main windows? You can have one and open more windows using simple QWidgets derived classes. -
@vel1024
QMainWindow
is actually nothing "different" or "special", it's just a window with a particular style. It is usual to only have one instance, but you can have multiple instances if you wish. Your interface sounds a little strange, but that's up to you. If you do decide to do this, you do not need to destroy and then recreate the windows, consider usinghide()
to hide and thenshow()
to reshow them.