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++
QtWS25 Last Chance

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.2k 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.
  • nageshN nagesh

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

    Jasmin QuinnJ Offline
    Jasmin QuinnJ Offline
    Jasmin Quinn
    wrote on last edited by
    #31
    This post is deleted!
    1 Reply Last reply
    0
    • nageshN nagesh

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

      Jasmin QuinnJ Offline
      Jasmin QuinnJ Offline
      Jasmin Quinn
      wrote on last edited by
      #32

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

      1 Reply Last reply
      0
      • nageshN Offline
        nageshN Offline
        nagesh
        wrote on last edited by
        #33

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

        Jasmin QuinnJ 1 Reply Last reply
        0
        • nageshN nagesh

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

          Jasmin QuinnJ Offline
          Jasmin QuinnJ Offline
          Jasmin Quinn
          wrote on 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
          • nageshN Offline
            nageshN Offline
            nagesh
            wrote on 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

            Jasmin QuinnJ 1 Reply Last reply
            0
            • nageshN nagesh

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

              Jasmin QuinnJ Offline
              Jasmin QuinnJ Offline
              Jasmin Quinn
              wrote on 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
              • nageshN Offline
                nageshN Offline
                nagesh
                wrote on 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 Jasmin QuinnJ 2 Replies Last reply
                1
                • A Offline
                  A Offline
                  Anonymous_Banned275
                  wrote on 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
                  • nageshN nagesh

                    @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 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
                    • nageshN Offline
                      nageshN Offline
                      nagesh
                      wrote on last edited by
                      #40

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

                      1 Reply Last reply
                      1
                      • nageshN nagesh

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

                        Jasmin QuinnJ Offline
                        Jasmin QuinnJ Offline
                        Jasmin Quinn
                        wrote on 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 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

                          • Login

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