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. URGENT : How to Show Another Window From MainWindow in QT using c++
Forum Updated to NodeBB v4.3 + New Features

URGENT : How to Show Another Window From MainWindow in QT using c++

Scheduled Pinned Locked Moved Solved General and Desktop
qt creator
42 Posts 6 Posters 9.5k Views 2 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.
  • N Offline
    N Offline
    nagesh
    wrote on 27 Apr 2021, 12:45 last edited by
    #28

    @Jasmin-Quinn you are not following as suggested..

    Decide where do you want to have the instance of game.

    Follow only the steps 1)2)3) suggested earlier and make sure main is not having any game object pointer and
    MainWindow.h also should not have any game*.

    J 1 Reply Last reply 27 Apr 2021, 13:08
    0
    • N nagesh
      27 Apr 2021, 12:45

      @Jasmin-Quinn you are not following as suggested..

      Decide where do you want to have the instance of game.

      Follow only the steps 1)2)3) suggested earlier and make sure main is not having any game object pointer and
      MainWindow.h also should not have any game*.

      J Offline
      J Offline
      Jasmin Quinn
      wrote on 27 Apr 2021, 13:08 last edited by
      #29

      @nagesh I can't do that . Without the game object pointer in main.cpp it generates this error
      21dd475e-3a65-4192-bdc8-7a4ef91fb0fa-image.png

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nagesh
        wrote on 27 Apr 2021, 13:17 last edited by
        #30

        @Jasmin-Quinn move the declaration of
        Game *game to MainWindow.h as global declaration

        J 2 Replies Last reply 27 Apr 2021, 13:26
        0
        • N nagesh
          27 Apr 2021, 13:17

          @Jasmin-Quinn move the declaration of
          Game *game to MainWindow.h as global declaration

          J Offline
          J Offline
          Jasmin Quinn
          wrote on 27 Apr 2021, 13:26 last edited by
          #31
          This post is deleted!
          1 Reply Last reply
          0
          • N nagesh
            27 Apr 2021, 13:17

            @Jasmin-Quinn move the declaration of
            Game *game to MainWindow.h as global declaration

            J Offline
            J Offline
            Jasmin Quinn
            wrote on 27 Apr 2021, 13:37 last edited by
            #32

            @nagesh Done
            c8cf47ae-f4cf-4163-ad0c-d14158c5d82f-image.png

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nagesh
              wrote on 27 Apr 2021, 13:50 last edited by
              #33

              @Jasmin-Quinn I hope Game *game declared in MainWindow.h only..

              J 1 Reply Last reply 27 Apr 2021, 14:07
              0
              • N nagesh
                27 Apr 2021, 13:50

                @Jasmin-Quinn I hope Game *game declared in MainWindow.h only..

                J Offline
                J Offline
                Jasmin Quinn
                wrote on 27 Apr 2021, 14:07 last edited by
                #34

                @nagesh It is i promise . Is it nomral that my compiler couldn't find the moc_mainwindow.cpp file tho ?

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  nagesh
                  wrote on 27 Apr 2021, 14:23 last edited by
                  #35

                  @Jasmin-Quinn paste MainWindow.h code here
                  Hope it's having below statements in the beginning
                  #ifdef MAINWINDOW_H
                  #define MAINWINDOW_H

                  J 1 Reply Last reply 27 Apr 2021, 16:54
                  0
                  • N nagesh
                    27 Apr 2021, 14:23

                    @Jasmin-Quinn paste MainWindow.h code here
                    Hope it's having below statements in the beginning
                    #ifdef MAINWINDOW_H
                    #define MAINWINDOW_H

                    J Offline
                    J Offline
                    Jasmin Quinn
                    wrote on 27 Apr 2021, 16:54 last edited by
                    #36

                    @nagesh ```
                    #ifndef MAINWINDOW_H
                    #define MAINWINDOW_H
                    #include "joueur.h"
                    #include "partie.h"
                    #include "game.h"
                    #include "qcustomplot.h"
                    #include "notepad.h"
                    #include "camera.h"
                    #include "qrplusplus.h"
                    #include <QPropertyAnimation>

                    #include <QMainWindow>

                    QT_BEGIN_NAMESPACE
                    namespace Ui { class MainWindow; }
                    QT_END_NAMESPACE

                    Game *game;

                    class MainWindow : public QMainWindow
                    {
                    Q_OBJECT

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

                    private slots:
                    void on_ajouter_joueur_clicked();

                    void on_supprimer_joueur_clicked();
                    
                    void on_tab_afficher_joueur_activated(const QModelIndex &index);
                    
                    void on_modifier_joueur_clicked();
                    
                    void on_ajouter_partie_clicked();
                    
                    void on_tab_afficher_partie_activated(const QModelIndex &index);
                    
                    void on_supprimer_partie_clicked();
                    
                    void on_modifier_partie_clicked();
                    
                    void on_chercher_joueur_clicked();
                    
                    void on_chercher_partie_clicked();
                    
                    void on_trier_joueur_clicked();
                    
                    void on_trier_partie_clicked();
                    
                    void on_imprimer_partie_clicked();
                    
                    void on_excel_joueur_clicked();
                    
                    void showTime();
                    
                    void on_envoyer_mail_released();
                    
                    void on_afficher_tout_joueurs_clicked();
                    
                    void on_afficher_tout_parties_clicked();
                    
                    void on_stat_joueur_clicked();
                    
                    void on_notes_clicked();
                    
                    
                    
                    void on_ajouter_photo_j_clicked();
                    
                    void on_prendre_photo_clicked();
                    
                    void on_qrcode_clicked();
                    
                    void on_lancer_partie_clicked();
                    

                    private:
                    Ui::MainWindow *ui;
                    Joueur J;
                    Partie P;

                    Notepad *notepad;
                    Camera *camera;
                    QRplusplus *qrcode;
                    QPropertyAnimation * animation;
                    QCustomPlot *customPlot;
                    
                    
                    QString fileNameImage ;
                    QPixmap photo ;
                    QByteArray image;
                    QPixmap pixmap;
                    QByteArray array;
                    

                    };
                    #endif // MAINWINDOW_H

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      nagesh
                      wrote on 27 Apr 2021, 23:35 last edited by
                      #37

                      @Jasmin-Quinn okay fine, I repeat that my first post is the solution to this application integration.

                      I repost the working solution. (I tried integrating github project which is working fine )

                      Solution as per the existing implementation of chessboard application (Just to make the integration works fine)
                      1)Copy the required files(chess project files) to the existing project.

                      2)In Mainwindow.cpp create the global game object pointer;
                      Game *game=nullptr;
                      //make sure Game *game; exists only in the Mainwindow.cpp
                      //Earlier crash was because there were two instance game * one in Manwindow.h as member variable and other with main.cpp.

                      3)In Mainwindow.cpp include the game.h file
                      #include "game.h"

                      4)In on_lancer_partie_clicked() create the instance of it
                      game = new Game();
                      game->show();
                      game->displayMainMenu();

                      Note: Assumption that github code remains unaltered.

                      A J 2 Replies Last reply 28 Apr 2021, 00:13
                      1
                      • A Offline
                        A Offline
                        Anonymous_Banned275
                        wrote on 28 Apr 2021, 00:01 last edited by
                        #38

                        So basically back to square one.
                        I still believe that SUB_DIRS would make life easier.
                        ( adding game code from github was a snap - but it works as independent project only.

                        The qmake / management part of SUB_DIRS is OK, however, it definitely requires better knowledge of "make" ( am I repeating myself here?).

                        There are many options in qmake and it will just take some time to figure out how to

                        have (main) project
                        and be able to select real sub-project.

                        I have done that on "C level " - using MDI / QProcess and I'll try to get same result
                        using qmake.

                        1 Reply Last reply
                        0
                        • N nagesh
                          27 Apr 2021, 23:35

                          @Jasmin-Quinn okay fine, I repeat that my first post is the solution to this application integration.

                          I repost the working solution. (I tried integrating github project which is working fine )

                          Solution as per the existing implementation of chessboard application (Just to make the integration works fine)
                          1)Copy the required files(chess project files) to the existing project.

                          2)In Mainwindow.cpp create the global game object pointer;
                          Game *game=nullptr;
                          //make sure Game *game; exists only in the Mainwindow.cpp
                          //Earlier crash was because there were two instance game * one in Manwindow.h as member variable and other with main.cpp.

                          3)In Mainwindow.cpp include the game.h file
                          #include "game.h"

                          4)In on_lancer_partie_clicked() create the instance of it
                          game = new Game();
                          game->show();
                          game->displayMainMenu();

                          Note: Assumption that github code remains unaltered.

                          A Offline
                          A Offline
                          Anonymous_Banned275
                          wrote on 28 Apr 2021, 00:13 last edited by
                          #39

                          @nagesh said in URGENT : How to Show Another Window From MainWindow in QT using c++:

                          @Jasmin-Quinn okay fine, I repeat that my first post is the solution to this application integration.

                          I repost the working solution. (I tried integrating github project which is working fine )

                          Solution as per the existing implementation of chessboard application (Just to make the integration works fine)
                          1)Copy the required files(chess project files) to the existing project.

                          2)In Mainwindow.cpp create the global game object pointer;
                          Game *game=nullptr;
                          //make sure Game *game; exists only in the Mainwindow.cpp
                          //Earlier crash was because there were two instance game * one in Manwindow.h as member variable and other with main.cpp.

                          3)In Mainwindow.cpp include the game.h file
                          #include "game.h"

                          4)In on_lancer_partie_clicked() create the instance of it
                          game = new Game();
                          game->show();
                          game->displayMainMenu();

                          Note: Assumption that github code remains unaltered.

                          If I borrow Qt "cALLBACK" terminology you probably want
                          main window event loop
                          game project event loop

                          or in human -
                          run game project event loop INSIDE main project event loop
                          or in "pseudocode " (no buttons pushing )

                          int main(int argc, char *argv[])
                          {
                          QApplication main ptoject (argc, argv); main project event loop
                          QApplication game project (argc, argv); game project event loop
                          game = new Game();
                          game->show();
                          game->displayMainMenu();
                          return game project .exec();
                          return main project .exec();
                          }

                          1 Reply Last reply
                          0
                          • N Offline
                            N Offline
                            nagesh
                            wrote on 28 Apr 2021, 00:57 last edited by
                            #40

                            @AnneRanch AFAIK one instance of QApplication & one event loop required in main

                            1 Reply Last reply
                            1
                            • N nagesh
                              27 Apr 2021, 23:35

                              @Jasmin-Quinn okay fine, I repeat that my first post is the solution to this application integration.

                              I repost the working solution. (I tried integrating github project which is working fine )

                              Solution as per the existing implementation of chessboard application (Just to make the integration works fine)
                              1)Copy the required files(chess project files) to the existing project.

                              2)In Mainwindow.cpp create the global game object pointer;
                              Game *game=nullptr;
                              //make sure Game *game; exists only in the Mainwindow.cpp
                              //Earlier crash was because there were two instance game * one in Manwindow.h as member variable and other with main.cpp.

                              3)In Mainwindow.cpp include the game.h file
                              #include "game.h"

                              4)In on_lancer_partie_clicked() create the instance of it
                              game = new Game();
                              game->show();
                              game->displayMainMenu();

                              Note: Assumption that github code remains unaltered.

                              J Offline
                              J Offline
                              Jasmin Quinn
                              wrote on 28 Apr 2021, 10:22 last edited by
                              #41

                              @nagesh IT WORKKKSSS Thank youu !! How did i not think of that

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                Anonymous_Banned275
                                wrote on 28 Apr 2021, 17:38 last edited by
                                #42

                                Is it correct to say that now the "main project" has all the code of "chess" added so basically there is only one application running?

                                The objective to "have two windows" has been met, however, adding more "child applications" using same philosophy of "cut and paste" is not what " reusing code " means to me.

                                1 Reply Last reply
                                0

                                37/42

                                27 Apr 2021, 23:35

                                • Login

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