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

Reopen MainWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.3k Views
  • 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.
  • V Offline
    V Offline
    vel1024
    wrote on last edited by vel1024
    #1

    Hello,
    I made two mainwindow

    1. mainwindow.h & cpp
    2. 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
    
    
    jsulmJ 1 Reply Last reply
    0
    • V vel1024

      Hello,
      I made two mainwindow

      1. mainwindow.h & cpp
      2. 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
      
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • V Offline
        V Offline
        vel1024
        wrote on last edited by vel1024
        #3

        @jsulm

        thank you for your comment

        because, i'm a beginner so i don't know that i can't have two main windows

        jsulmJ JonBJ 2 Replies Last reply
        0
        • V vel1024

          @jsulm

          thank you for your comment

          because, i'm a beginner so i don't know that i can't have two main windows

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @vel1024 I didn't say you can't. You can.
          But I would not create one than one main window unless I really need to.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • V vel1024

            @jsulm

            thank you for your comment

            because, i'm a beginner so i don't know that i can't have two main windows

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @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 using hide() to hide and then show() to reshow them.

            V 1 Reply Last reply
            3
            • JonBJ JonB

              @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 using hide() to hide and then show() to reshow them.

              V Offline
              V Offline
              vel1024
              wrote on last edited by
              #6

              @JonB

              thank you for your comment

              1 Reply Last reply
              0
              • G Offline
                G Offline
                Georg-e
                wrote on last edited by Georg-e
                #7

                If your "myWindow" is just a window belong to the application you want to shut down. I'm afraid that we can hardly achieve that. We can't restart a window in a shuted down application LiteBlue

                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